android - How to detect app removed from the recent list -


i'm working on music app, , want stop service when user removes application recent list , not when first activity destroyed(because when user clicks back until app minimizes, in case first activity getting destroyed). please help.

i want stop service when user removes application recent list.

yes, can either using stopwithtask flag true service in manifest file.

example:

<service     android:enabled="true"     android:name=".myservice"     android:exported="false"     android:stopwithtask="true" /> 

or

if need event of application being removed recent list, , before stopping service, can use this:

<service     android:enabled="true"     android:name=".myservice"     android:exported="false"     android:stopwithtask="false" /> 

so service's method ontaskremoved called. (remember, won't called if set stopwithtask true).

public class myservice extends service {      @override     public void onstartservice() {         //your code     }      @override     public void ontaskremoved(intent rootintent) {         system.out.println("ontaskremoved called");         super.ontaskremoved(rootintent);         //do want         //stop service         this.stopself();     } } 

hope helps.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -