exodus-android-app icon indicating copy to clipboard operation
exodus-android-app copied to clipboard

Crash - android.app.BackgroundServiceStartNotAllowedException

Open Jean-BaptisteC opened this issue 2 years ago • 3 comments

Exception android.app.BackgroundServiceStartNotAllowedException:
  at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1918)
  at android.app.ContextImpl.startService (ContextImpl.java:1874)
  at android.content.ContextWrapper.startService (ContextWrapper.java:827)
  at android.content.ContextWrapper.startService (ContextWrapper.java:827)
  at org.eu.exodus_privacy.exodusprivacy.MainActivity$startInitial$1.invoke (SourceFile:10)
  at org.eu.exodus_privacy.exodusprivacy.MainActivity$startInitial$1.invoke (SourceFile:1)
  at org.eu.exodus_privacy.exodusprivacy.MainActivity$sam$androidx_lifecycle_Observer$0.onChanged
  at androidx.lifecycle.LiveData.c (SourceFile:30)
  at androidx.lifecycle.LiveData.d (SourceFile:16)
  at androidx.lifecycle.LiveData$c.h (SourceFile:24)
  at androidx.lifecycle.LiveData$LifecycleBoundObserver.d (SourceFile:30)
  at androidx.lifecycle.x$b.a (SourceFile:25)
  at androidx.lifecycle.x.h (SourceFile:83)
  at androidx.lifecycle.x.p (SourceFile:80)
  at androidx.lifecycle.x.l (SourceFile:35)
  at androidx.lifecycle.x.i (SourceFile:15)
  at androidx.lifecycle.l0$b.a (SourceFile:41)
  at androidx.lifecycle.l0$c.onActivityPostStarted (SourceFile:10)
  at android.app.Activity.dispatchActivityPostStarted (Activity.java:1496)
  at android.app.Activity.performStart (Activity.java:8611)
  at android.app.ActivityThread.handleStartActivity (ActivityThread.java:3922)
  at android.app.servertransaction.TransactionExecutor.performLifecycleSequence (TransactionExecutor.java:221)
  at android.app.servertransaction.TransactionExecutor.cycleToPath (TransactionExecutor.java:201)
  at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:173)
  at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:97)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2437)
  at android.os.Handler.dispatchMessage (Handler.java:106)
  at android.os.Looper.loopOnce (Looper.java:211)
  at android.os.Looper.loop (Looper.java:300)
  at android.app.ActivityThread.main (ActivityThread.java:8294)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:580)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1028)

https://github.com/Exodus-Privacy/exodus-android-app/blob/78f5d380d42a63ff60b1638e8ea74c84b97af1a7/app/src/main/java/org/eu/exodus_privacy/exodusprivacy/MainActivity.kt#L97

Jean-BaptisteC avatar Sep 07 '23 15:09 Jean-BaptisteC

Some links to help to fix:

  • https://developer.android.com/develop/background-work/services/foreground-services?authuser=4#background-start-restrictions
  • https://developer.android.com/about/versions/12/behavior-changes-12?authuser=4#foreground-service-launch-restrictions
  • https://proandroiddev.com/foreground-service-launch-restrictions-android12-ee00bf8a1674

Jean-BaptisteC avatar Dec 27 '23 09:12 Jean-BaptisteC

Migration to WorkManager should be considered that will also allow to automatically update the database in background.

theimpulson avatar Mar 19 '24 08:03 theimpulson

I didn't like WorkManager:

  • Take too much space
  • Need new permissions
  • Need a own room database

And with most version of Android, background service is too restrictive and need regularly to update code to respect rules of Google.

Jean-BaptisteC avatar Mar 19 '24 10:03 Jean-BaptisteC