How To Execute Code Before Android App Is Killed
I have an Android app that connects to surrounding devices currently running the same app, even if in background. To do this, I use WiF-Direct to advertise the fact that I am curre
Solution 1:
You should be able to do this with a Service.
Start a service when your app was started. Override the onTaskRemoved method
@OverridepublicvoidonTaskRemoved(Intent rootIntent)
{
}
In this method do what you have to do. More detailed answer can be found here: How to know when my app has been killed? (2 answer)
Solution 2:
The best implementation might be to have another service running that queries the your app is in foreground(i.e. running)
You can run the query to check periodically say every 60 sec. Then if the app isn't running. You can stop the WiFi Direct service and subsequently stop self.
Post a Comment for "How To Execute Code Before Android App Is Killed"