5

I am developing an Android app that also includes a Service. The 'Swipe to Exit' functionality of the ICS recent apps list closes the app as expected, but the Service just exits along with it and does not receive an onTaskRemoved() callback to tell it to clean up (or onDestroy() for that matter):

http://developer.android.com/reference/android/app/Service.html#onTaskRemoved(android.content.Intent)

This leaves the notification icon in the status bar and I need to make sure this is removed when the app exits.

I've tried setting android:stopWithTask to false (and true) in Manifest.xml and it seems to make no difference.

    <service 
        android:name="com.test.TestService"
        android:stopWithTask="false" 
    />

Any ideas why the onTaskRemoved() callback is not being received?

Megsy
  • 51
  • 1
  • 3

3 Answers3

2

When the Service started with startService() and onTaskRemoved() was called when the app removed from recent-apps-list by swipe.

But if the Service started with bindService(), then onTaskRemoved() never gets called. Please check reference here to see if it resolves your problem.

Community
  • 1
  • 1
Chine Gary
  • 123
  • 1
  • 8
0

If your Service is running at that instant when user swipes, then this methods will be called.

Make sure, your Service is running at that instant.

Sufian
  • 6,405
  • 16
  • 66
  • 120
Meher
  • 2,545
  • 3
  • 26
  • 53
0

What I did is each activity start a specified service with startService() at onCreate() and stop it with stopService() at onDestroy(),during the life time,when swiping happened and the activity is at the top of task,the onTaskMoved will be called,then we could monitor the swipe behavior.The downside is each activity has to be equipped with a paired service,that’s ugly when there are various activity in your app.

Chine Gary
  • 123
  • 1
  • 8