Question

I have a rather curious problem. I have a non bound Service that i call using the code below from my main activity when the app is opened.

//some code checks if the service is awake. if not then the code below is called        
Intent serviceIntent = new Intent(this, SMS_Listener_Service.class);
startService(serviceIntent);

When a new sms comes in the Service waits for 3 seconds via a timer to ensure the content observer has saved data to the internal sms db. after that it makes a call to an intentservice to do the heavy lifting.

For Unknown reasons,the Service will sometimes hang and get stuck on "restarting (see image)"

The curious thing is that even attempting to Force stop the service in the applications section doesnt work. It disappears momentarily and then appears again with the same message. using stopService in code doesnt work either and the OnDestroy Method within the Service is never called. The only way around it is to restart the phone.

Problem is that when it is in this state it doesn't function.(its meant to parse incoming Sms Messages)

I'm running this on a galaxy note 3 with android 4.3

"Hanging Service"

My suspicion is that the Intentservice doing the actual parsing does not complete and therefore the call for the Service to stop itself is never called.

My question is, is there a way of forcing an intentservice that has hung to stop?

this is the code in StartCommand in the service

  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);

    if (!blnAutoSyncisEnabled) {
        stopSelf();
        return 0;
    } else {
        return START_STICKY;

    }

 }

more detailed view of same question here https://stackoverflow.com/posts/21077517/edit

Was it helpful?

Solution

This may not be a very elegant solution but you can call stopSelf() directly in the service's onCreate() method and handle the actual action in it's onDestroy() before calling super.onDestroy().

I had a similiar problem which I fixed this way. Maybe this will solve your problem too. Good luck. ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top