How to detect app removed from the recent list?

后端 未结 3 515
忘掉有多难
忘掉有多难 2020-11-29 09:22

I\'m working on a music app, and I want stop the service when user removes the application from the recent list and not when the first activity is destroyed(because when use

3条回答
  •  醉话见心
    2020-11-29 09:56

    The last answer didn't work for me (I am using API 29). I looked up in the Javadoc of the onTaskRemoved function and saw the following instruction: "If you have set {android:stopWithTask}, then you will not receive this callback; instead, the service will simply be stopped."

    So, all I got to do is to remove this line (android:stopWithTask="false") from the manifest and it worked just fine.

    This is the updated code in the manifest file:

    
    

提交回复
热议问题