Using the Scroll to Exit feature in the list of recent ICS applications

I am developing an Android application that also includes a Service. The Scroll to Exit function in the list of recent ICS applications closes the application as expected, but the Service simply exits with it and does not receive the onTaskRemoved () callback to tell it to clear (or onDestroy ())):

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

This leaves a notification icon in the status bar, and I need to make sure that it is removed when the application exits.

I tried setting android: stopWithTask to false (and true) in Manifest.xml and that doesn't seem to matter.

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

Any ideas why the onTaskRemoved () callback is not accepted?

+5
source share
3 answers

When Servicestarting with startService()and onTaskRemoved()is called when the application is removed from the list of recent applications, swipe the screen.

But if it Servicestarts with bindService(), it is onTaskRemoved()never called. Please check here to find out if it solves your problem.

+2
source

If yours Serviceworks while the user is searching, then these methods will be called.

Make sure yours is Servicerunning at this point.

0
source

What I did is every action that starts the specified service with startService () on onCreate () and stops it with stopService () in onDestroy (), during the life cycle when the scroll occurs and the activity is in at the top of the task, onTaskMoved will be called, then we could track the swipe behavior. The disadvantage is that each action must be equipped with a paired service, which is ugly when there are various actions in your application.

0
source

All Articles