kontalk / androidclient

Kontalk official Android client
https://www.kontalk.org
GNU General Public License v3.0
572 stars 195 forks source link

Cannot start RegistrationService while in background #1305

Open daniele-athome opened 4 years ago

daniele-athome commented 4 years ago

Apparently the postDelayed trick didn't work :-)

Fatal Exception: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=org.kontalk/.service.registration.RegistrationService }: app is in background uid UidRecord{3356b13 u0a237 CAC  bg:+12m37s722ms idle change:cached procs:1 seq(0,0,0)}
       at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1616)
       at android.app.ContextImpl.startService(ContextImpl.java:1571)
       at android.content.ContextWrapper.startService(ContextWrapper.java:669)
       at org.kontalk.service.registration.RegistrationService.start(RegistrationService.java:1492)
       at org.kontalk.ui.NumberValidation$5.run(NumberValidation.java:421)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7398)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:919)

Move the start() call to onResume and ensure the RegistrationService won't do first-time stuff after the first onStartCommand.