"Start At Boot" crashing when device boots up.

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

I turn on "Start At Boot" to make sure a service will start if the user reboots their Android device but it crashes with this message:

B4X:
The application <app name> (process <process name>) has stopped unexpectedly. Please try again

The only choice in the error dialogue box is "Force Close". After a while has passed maybe a few minutes the message will be displayed again. The only way for me to make it stop is to run the app to start the service.

Thanks.
 

rleiman

Well-Known Member
Licensed User
Longtime User
I found this in the logs but I don't know how to fix it.

B4X:
threadid=1: thread exiting with uncaught exception (group=0x4001d800)
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start service wake.up.phone.devicewakupservice@44ee3620 with Intent { cmp=wake.up.phone/.devicewakupservice (has extras) }: java.lang.RuntimeException: java.lang.IllegalStateException: Interval must be larger than 0.
   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3063)
   at android.app.ActivityThread.access$3600(ActivityThread.java:125)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2096)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:4627)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)


   at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Interval must be larger than 0.
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:145)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:89)
   at wake.up.phone.devicewakupservice.handleStart(devicewakupservice.java:61)
   at wake.up.phone.devicewakupservice.onStartCommand(devicewakupservice.java:46)
   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3053)
   ... 10 more
Caused by: java.lang.IllegalStateException: Interval must be larger than 0.
   at anywheresoftware.b4a.objects.Timer.setEnabled(Timer.java:77)
   at wake.up.phone.devicewakupservice._service_start(devicewakupservice.java:159)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
   ... 14 more
asec mount anywheresoftware.b4a.samples.xmlsax-1 {} 1000


asec path anywheresoftware.b4a.samples.xmlsax-1


 prescan time: 3995ms

It's jibberish to me.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
It works if I start the service from the app.

Can you tell me what to add to my coding to ensure the time starts with a positive number when booting up the Android device?

Thanks.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Here is the service. It's not big but I hope you can find where I'm going wrong and show me what to fix.

Thanks.

In the Main module:
B4X:
   If FirstTime Then
   
      ' Set first time defaults.
      '-------------------------
      blnChangesHaveBeenMade = False
      
      intTimeToKeepActive = 1000
      intTimeToKeepInactive = 5 * 60000
      
   End If

In the service module:
B4X:
'Service module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
   ' Phone.
   '-------
   Dim pw As PhoneWakeState
   
   ' Timers.
   '--------
   Dim tmrTimeToKeepActive As Timer
   Dim tmrTimeToKeepInactive As Timer
   
End Sub

Sub Service_Create

End Sub

Sub Service_Start (StartingIntent As Intent)
   
'   ToastMessageShow("Setting time to keep active.", True)
   
   tmrTimeToKeepActive.Initialize("TimeToKeepActive", main.intTimeToKeepActive)
   tmrTimeToKeepActive.Enabled = True

   pw.PartialLock
End Sub

Sub Service_Destroy

   ToastMessageShow("Service ended.", True)

   pw.ReleasePartialLock
End Sub

Sub TimeToKeepActive_Tick
   
'   ToastMessageShow("Time to keep active is now over.", True)

   pw.ReleasePartialLock

'   ToastMessageShow("Setting time to keep inactive.", True)

   tmrTimeToKeepInactive.Initialize("TimeToKeepInactive", main.intTimeToKeepInactive)
   tmrTimeToKeepInactive.Enabled = True

   tmrTimeToKeepActive.Enabled = False
End Sub

Sub TimeToKeepInactive_Tick

'   ToastMessageShow("Time to keep inactive is now over.", True)

   pw.PartialLock

'   ToastMessageShow("Setting time to keep active.", True)
   
   tmrTimeToKeepActive.Initialize("TimeToKeepActive", main.intTimeToKeepActive)
   tmrTimeToKeepActive.Enabled = True

   tmrTimeToKeepInactive.Enabled = False
End Sub

Sub ResetTimers (pTimeToKeepActive As Int, pTimeToKeepInactive As Int)

   tmrTimeToKeepActive.Enabled = False
   tmrTimeToKeepInactive.Enabled = False
   
   tmrTimeToKeepActive.Initialize("TimeToKeepActive", pTimeToKeepActive)
   tmrTimeToKeepInactive.Initialize("TimeToKeepInactive", pTimeToKeepInactive)

   tmrTimeToKeepActive.Enabled = True
   tmrTimeToKeepInactive.Enabled = True
End Sub

Sub TurnOffTimers

   tmrTimeToKeepActive.Enabled = False
   tmrTimeToKeepInactive.Enabled = False
End Sub   

Sub TurnPartialLockOn

   pw.PartialLock
End Sub


You should check your code (Sub Service_Started) and check how you initialize the timer.
 
Last edited:
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
Probably because the activity main is not started when booting.

I would suggest in main, writing the intervals to a list and save it to a text file in dirdefault. When the service is created or started, read the list and start the timer with the interval.

Or try startactivity, and activity finish after the activity has been created.

Tomas

Sent from my SE Xperia Play using Tapatalk.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Here's what I did since main is not called if the Android device was shut down:

B4X:
Sub Service_Start (StartingIntent As Intent)
   
'   ToastMessageShow("Setting time to keep active.", True)

   ' Check if the Android device was shut down and use defaults if needed.
   '----------------------------------------------------------------------
   If Main.intTimeToKeepActive = 0 Then

      ToastMessageShow("'Wake Up Phone' is now using defaults. Change settings if needed.", True)

      Main.intTimeToKeepActive = 1000
      Main.intTimeToKeepInactive = 5 * 60000
   End If      

   tmrTimeToKeepActive.Initialize("TimeToKeepActive", main.intTimeToKeepActive)
   tmrTimeToKeepActive.Enabled = True

   pw.PartialLock
End Sub

Now it doesn't crash. :)

Probably because the activity main is not started when booting.

I would suggest in main, writing the intervals to a list and save it to a text file in dirdefault. When the service is created or started, read the list and start the timer with the interval.

Or try startactivity, and activity finish after the activity has been created.

Tomas

Sent from my SE Xperia Play using Tapatalk.
 
Upvote 0
Top