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 user clicks back back until app minimizes, in that case first activity is also getting destroyed). Please help.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Im posting this answer, since the chosen as best solution was not working for me.
This is the updated version:
First create this service class:
Then, declare this way your service in the manifest label:
Now, just start the service wherever you want to do something before your app closing.
Yes, you can either do that using
stopWithTask
flag astrue
for Service in Manifest file.Example:
OR
If you need event of application being removed from recent list, and do something before stopping service, you can use this:
So your service's method
onTaskRemoved
will be called. (Remember, it won't be called if you setstopWithTask
totrue
).Hope this helps.