Alarmio
Alarmio copied to clipboard
SleepReminderService not calling startForeground
This is a problem. This causes a crash. It... probably shouldn't. Ideally it should figure out if it's going to call startForeground
before starting... and not just decide not to once it's started. I can't remember what the reasoning was behind this.
Full stack trace:
android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{84272d3 u0 me.jfenn.alarmio/.services.SleepReminderService}
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1745)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Update: I've remembered why this is necessary -
The service registers a BroadcastReceiver and obtains an instance of PowerManager to detect the screen on/off state while it is running; the service can be started and remain running as long as an alarm is in the "sleep" period, but the service will only be in the foreground (and thus displaying a persistent notification) while the screen is on. Unfortunately, the screen on/off intents cannot be registered from the manifest, so if I cannot find a way around this crash then it may spell the end for this feature in Oreo and above.