Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalStateException: "not allowed to start service intent - app is in background" on Android 8+ #37

Closed
mathisdt opened this issue Jun 4, 2018 · 2 comments
Assignees
Milestone

Comments

@mathisdt
Copy link
Owner

mathisdt commented Jun 4, 2018

java.lang.IllegalStateException: Not allowed to start service Intent { cmp=org.zephyrsoft.trackworktime/.location.LocationTrackerService (has extras) }: app is in background uid UidRecord{fbd005 u0a305 RCVR bg:+4m57s939ms idle procs:2 seq(223,223,223)}
	at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1538)
	at android.app.ContextImpl.startService(ContextImpl.java:1484)
	at android.content.ContextWrapper.startService(ContextWrapper.java:663)
	at org.zephyrsoft.trackworktime.Basics.startLocationTrackerService(Basics.java:361)
	at org.zephyrsoft.trackworktime.Basics.checkLocationBasedTracking(Basics.java:341)
	at org.zephyrsoft.trackworktime.Basics.safeCheckLocationBasedTracking(Basics.java:218)
	at org.zephyrsoft.trackworktime.Basics.periodicHook(Basics.java:196)
	at org.zephyrsoft.trackworktime.Watchdog.onReceive(Watchdog.java:34)
	at android.app.ActivityThread.handleReceiver(ActivityThread.java:3390)
	at android.app.ActivityThread.-wrap18(Unknown Source:0)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1780)
	at android.os.Handler.dispatchMessage(Handler.java:105)
	at android.os.Looper.loop(Looper.java:164)
	at android.app.ActivityThread.main(ActivityThread.java:6938)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Starting with API level 21 (Android 5.0 Lollipop), the JobScheduler is available and apparently under Oreo it has to be used if the user didn't grant an exception.

Anyone may go to "Settings" -> "Apps & notifications" -> "Advanced" -> "Special app access" -> "Battery optimization", select "All apps", tap on "Track Work Time" in the list and select "Don't optimize". This will exclude TWT from some restrictions regarding background work.

@mathisdt mathisdt self-assigned this Jun 5, 2018
mathisdt added a commit that referenced this issue Jun 5, 2018
…is in background" on Android 8+ by starting the services in the foreground (which means there is a persistent notification visible in Android 8+ while location and/or WiFi check is active) #37
@mathisdt
Copy link
Owner Author

mathisdt commented Jun 5, 2018

It seems that starting the services in the foreground is the better way.

mathisdt added a commit that referenced this issue Jun 6, 2018
…is in background" on Android 8+ by starting the services in the foreground (which means there is a persistent notification visible in Android 8+ while location and/or WiFi check is active) #37
@mathisdt mathisdt closed this as completed Jun 6, 2018
@mathisdt mathisdt added this to the v1.0.3 milestone Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant