I get the following exception output from Device Monitor:
//FATAL EXCEPTION: main //Process: com.xxx.yyy, PID: 11584 //android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground() // at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1881) // at android.os.Handler.dispatchMessage(Handler.java:105) // at android.os.Looper.loop(Looper.java:164) // at android.app.ActivityThread.main(ActivityThread.java:6944) // 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) I have 4 services in my App and all of them basically looks like this:
public class MyService extends Service { private static final int forgroundId = 55544433; //Unique for each Service private Notification notification; @Override public void onCreate() { super.onCreate(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { initNotification(); //Creates a notification startForeground(forgroundId, notification); //Start foreground, very first thing.. //Do Stuff return START_STICKY; } } To start the services, I use the following:
Intent i = new Intent(context, MyService.class); i.SetAction("myaction.."); i.PutExtra(...); android.support.v4.content.ContextCompat.startForegroundService(context, i); I have a few other libraries which also might have services starting included in my project:
- Fabric.io
- Firebase Messaging/Analytics/etc.
- Google Play Services Analytics/GCM/Tasks/etc.
- Android-Job from Evernote
The problem is, I can not figure out exactly which service is causing this error. If the class was included in the exception, I wouldn't be here...
Is there anyway to [catch/throw/I don't know] any hint as to where the exception is coming from?
I have read all the following posts with no luck at all:
This happens only sometimes when opening the app, so to me my code is correct?
I only want to know how to figure out which service this is coming from.
WorkManager(or Android-Job, since you seem to be using that already), rather than rolling your own service for this.onDestroyandonLowMemorywhich stopped the service fixed the issue for me