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

Crash when i wake app #4896

Closed
Jean-BaptisteC opened this issue Mar 22, 2023 · 3 comments
Closed

Crash when i wake app #4896

Jean-BaptisteC opened this issue Mar 22, 2023 · 3 comments
Labels

Comments

@Jean-BaptisteC
Copy link
Contributor

App crash when i wake app after app is background

How to Reproduce

  • I have used streetcomplete in street to answer at quests
  • I have leave ST and keep app open in background
  • 10 minutes after, i have try to reopen streetcomplete -> app crash with pop-up to send logs
java.lang.RuntimeException: Unable to stop activity
{de.westnordost.streetcomplete/de.westnordost.streetcomplete.screens.MainActivity}:
android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground
false: service de.westnordost.streetcomplete/.data.download.DownloadService
at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:5185)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:5157)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:5222)
at android.app.servertransaction.StopActivityItem.execute(StopActivityItem.java:43)
at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:179)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2303)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7884)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to
mAllowStartForeground false: service de.westnordost.streetcomplete/.data.download.DownloadService
at
android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
at
android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
at android.os.Parcel.readParcelableInternal(Parcel.java:4816)
at android.os.Parcel.readParcelable(Parcel.java:4778)
at android.os.Parcel.createExceptionOrNull(Parcel.java:3006)
at android.os.Parcel.createException(Parcel.java:2995)
at android.os.Parcel.readException(Parcel.java:2978)
at android.os.Parcel.readException(Parcel.java:2920)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6079)
at android.app.Service.startForeground(Service.java:743)
at de.westnordost.streetcomplete.data.download.DownloadService.updateShowNotification(DownloadService.kt:98)
at de.westnordost.streetcomplete.data.download.DownloadService.setShowNotification(DownloadService.kt:53)
at de.westnordost.streetcomplete.data.download.DownloadService.access$setShowNotification(DownloadService.kt:33)
at
de.westnordost.streetcomplete.data.download.DownloadService$Interface.setShowDownloadNotification(DownloadService.kt:113)
at de.westnordost.streetcomplete.data.download.DownloadController.setShowNotification(DownloadController.kt:41)
at de.westnordost.streetcomplete.screens.MainActivity.onStop(MainActivity.kt:236)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1584)
at android.app.Activity.performStop(Activity.java:8563)
at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:5177)
... 14 more

Versions affected
v52.0-beta1
Pixel 6 - Android 13

@Helium314
Copy link
Collaborator

Helium314 commented Mar 27, 2023

See https://developer.android.com/guide/components/foreground-services#background-start-restriction-exemptions
Apparently starting a service in MainActivity.onStop is not allowed as stopping is not "transitions from a user-visible state, such as an activity".
Maybe starting already onPause helps. (but what really helps is not so clear)

Alternatively you could make use of the last point: "The user turns off battery optimizations for your app"

@westnordost
Copy link
Member

Hm well, let's try if doing that in onPause solve the issue

@westnordost
Copy link
Member

FYI this has been a long-standing issue, but I didn't care about it so far because I put this in the "Android API is inconsistent and stupid" drawer, hoping that Android will fix it. As @Helium314 cited, the place where we call this method should be totally fine according to the documentation. Unless of course the Android system does not recognize "onStop" as "transitions from a user-visible state, such as an activity" but only "onPause". We will see.

If this does not solve the issue, then we'll just catch the exception and ignore it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants