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

ionic + cordova-plugin-background-mode Unable to resume activity / Service not registered #204

Closed
ishanthilina opened this issue Nov 10, 2016 · 10 comments

Comments

@ishanthilina
Copy link

Following is the code I use to enable the background mode in my ionic app.

$ionicPlatform.ready(function() {

  cordova.plugins.backgroundMode.setDefaults({ text:'Doing heavy tasks.'});

    cordova.plugins.backgroundMode.enable();
    
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }

    
    });

When I lock the screen when the app has focus (app is running in foreground) and try to unlock the screen again, I get the following exception.

11-10 00:43:42.426 5464-5464/com.ionicframework.mishuttle855256 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.ionicframework.mishuttle855256, PID: 5464 java.lang.RuntimeException: Unable to resume activity {com.ionicframework.mishuttle855256/com.ionicframework.mishuttle855256.MainActivity}: java.lang.IllegalArgumentException: Service not registered: de.appplant.cordova.plugin.background.BackgroundMode$1@7302666 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3273) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3304) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1513) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5697) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749) Caused by: java.lang.IllegalArgumentException: Service not registered: de.appplant.cordova.plugin.background.BackgroundMode$1@7302666 at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1085) at android.app.ContextImpl.unbindService(ContextImpl.java:1439) at android.content.ContextWrapper.unbindService(ContextWrapper.java:616) at de.appplant.cordova.plugin.background.BackgroundMode.stopService(BackgroundMode.java:250) at de.appplant.cordova.plugin.background.BackgroundMode.onResume(BackgroundMode.java:145) at org.apache.cordova.PluginManager.onResume(PluginManager.java:265) at org.apache.cordova.CordovaWebViewImpl.handleResume(CordovaWebViewImpl.java:448) at org.apache.cordova.CordovaActivity.onResume(CordovaActivity.java:265) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1268) at android.app.Activity.performResume(Activity.java:6345) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3258) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3304)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1513)  at android.os.Handler.dispatchMessage(Handler.java:111)  at android.os.Looper.loop(Looper.java:207)  at android.app.ActivityThread.main(ActivityThread.java:5697)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)

But if I switch to another app and then lock screen, this does not happen.

What am I doing wrong?

@katzer
Copy link
Owner

katzer commented Jan 2, 2017

@ishanthilina What plugin version do you use? Did you try out the latest master branch?

@jeroenverfallie
Copy link

jeroenverfallie commented May 8, 2017

@katzer We are receiving crash reports with the same error message, using the latest version of the plugin.

(OS Version: 6.0.1)

Fatal Exception: java.lang.RuntimeException: Unable to resume activity {_______.MainActivity}: java.lang.IllegalArgumentException: Service not registered: de.appplant.cordova.plugin.background.BackgroundMode$1@a3fba9d
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4225)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4327)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1865)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7331)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by java.lang.IllegalArgumentException: Service not registered: de.appplant.cordova.plugin.background.BackgroundMode$1@a3fba9d
       at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1160)
       at android.app.ContextImpl.unbindService(ContextImpl.java:1475)
       at android.content.ContextWrapper.unbindService(ContextWrapper.java:644)
       at de.appplant.cordova.plugin.background.BackgroundMode.stopService(BackgroundMode.java:258)
       at de.appplant.cordova.plugin.background.BackgroundMode.onResume(BackgroundMode.java:148)
       at org.apache.cordova.PluginManager.onResume(PluginManager.java:264)
       at org.apache.cordova.CordovaWebViewImpl.handleResume(CordovaWebViewImpl.java:448)
       at org.apache.cordova.CordovaActivity.onResume(CordovaActivity.java:275)
       at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1287)
       at android.app.Activity.performResume(Activity.java:7015)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4214)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4327)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1865)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:7331)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

@lkonzen-garupa
Copy link

I can't reproduce the case from @ishanthilina. But the Firebase Crashlytics are presenting a considerable number of cases with this error, using the latest master branch.

The error occur on multiple android versions, but more than 50% with Android 8.
image

Fatal Exception: java.lang.RuntimeException: Unable to resume activity {co.garupa/co.garupa.MainActivity}: java.lang.IllegalArgumentException: Service not registered: de.appplant.cordova.plugin.background.BackgroundMode$1@3ebfe70
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3421)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3461)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6123)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

Caused by java.lang.IllegalArgumentException: Service not registered: de.appplant.cordova.plugin.background.BackgroundMode$1@3ebfe70
       at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1289)
       at android.app.ContextImpl.unbindService(ContextImpl.java:1511)
       at android.content.ContextWrapper.unbindService(ContextWrapper.java:648)
       at de.appplant.cordova.plugin.background.BackgroundMode.stopService(BackgroundMode.java:267)
       at de.appplant.cordova.plugin.background.BackgroundMode.onResume(BackgroundMode.java:153)
       at org.apache.cordova.PluginManager.onResume(PluginManager.java:264)
       at org.apache.cordova.CordovaWebViewImpl.handleResume(CordovaWebViewImpl.java:450)
       at org.apache.cordova.CordovaActivity.onResume(CordovaActivity.java:275)
       at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1291)
       at android.app.Activity.performResume(Activity.java:6776)
       at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3398)
       at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3461)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6123)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

@katzer can you provide some help on this, something that we can use to try solve that error.

@Tioecomp
Copy link

Tioecomp commented Aug 29, 2019

Having the same problem android 8.0 and 9.0 did you have any sucess @lkonzen-garupa ?

@mirko77
Copy link

mirko77 commented Nov 6, 2019

How was this fixed?

@mirko77
Copy link

mirko77 commented Nov 18, 2019

Same issue on a couple of Android 9 devices. It does not happen always, it is random. Like once in three times...

@mirko77
Copy link

mirko77 commented Dec 4, 2019

@lkonzen-garupa, @Tioecomp did you solve the issue?

@lkonzen-garupa
Copy link

@mirko77 yes, it was solved by stop using this plugin.
Instead we start using this one, seen to be maintened.

https://bitbucket.org/TheBosZ/cordova-plugin-run-in-background

@mirko77
Copy link

mirko77 commented Dec 5, 2019

@lkonzen-garupa thank you, I will give it a try.

@mirko77
Copy link

mirko77 commented Dec 5, 2019

@lkonzen-garupa same issue with that plugin.

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

No branches or pull requests

6 participants