Android Question java.lang.IllegalStateException: Interval must be larger than 0.

powerino

Active Member
Licensed User
Hello, I have this problem with "BannerAd"... Error is here:

Sub Activity_Resume

timerInter.Enabled=True

End Sub

Somebody cna help me?

thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
And the answer is...

You are waiting for PermissionResult in Activity_Create:
B4X:
    rp.CheckAndRequest(rp.PERMISSION_WRITE_EXTERNAL_STORAGE)  '
   Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
Only later you are initializing the timer.

The result is that Activity_Resume is called before the timer is initialized.

Remember: From the code flow perspective Wait For is equivalent to Return.

Why do you need the external storage permission? Why not save it in File.DirInternal or RuntimePermissions.GetSafeDirDefaultExternal?

If you must request the permission then you need to handle the case where Activity_Resume is called before the permission is granted.

Tip: it would have been easier to help you if you posted the logs.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You are initializing Timer1 every time. You already get suggested to use it only when firsttime is true.
It does not help if you just IGNORE the suggestion.

Now
B4X:
        timer1.Initialize("timer1", 1000)

Change it to
B4X:
    If FirstTime Then
        timer1.Initialize("timer1", 1000)
    End If
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip:
B4X:
Sub CalculateMonth
   
   If monthTodayString = 1 Then
       monthString="Gennaio"
   else if monthTodayString = 2 Then
       monthString="Febbrai"
   else if monthTodayString = 3 Then
       monthString="Marzo"
   else if monthTodayString = 4 Then
       monthString="Aprile"
   else if monthTodayString = 5 Then
       monthString="Maggio"
   else if monthTodayString = 6 Then
       monthString="Giugno"
   else if monthTodayString = 7 Then
       monthString="Luglio"
   else if monthTodayString = 8 Then
       monthString="Agosto"
   else if monthTodayString = 9 Then
       monthString="Settembre"
   else if monthTodayString = 10 Then
       monthString="Ottobre"
   else if monthTodayString = 11 Then
       monthString="Novembre"
   else if monthTodayString = 12 Then
       monthString="Dicembre"
   End If
   
End Sub
Equivalent to:
B4X:
Sub CalculateMonth
   Dim months() As String = Array As String("Gennaio", "Febbrai", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", _
       "Settembre", "Ottobre", "Novembre", "Dicembre")
   monthString = months(monthTodayString - 1)
End Sub
You can of course make it a global variable.
 
Upvote 0

powerino

Active Member
Licensed User
Ok Erel thanks. I need to re-open the interstitial on activity_resume, but the open is in loop... how to open ONLY when I close another Activity and re-open Main activity?
 
Upvote 0
Top