I have an app that automatically transmits location data to servers in the background (yes, this is necessary) but needs to do it while the activity is destroyed to save memory (i.e. onDestroy()
won't work) but I want my app to terminate these operations when "swiped away" in the running applications view.
Is it even necessary to do this or will threads be interrupted automatically?
EDIT: I learned about services myself, but I am going to award the bounty to the person with the most comprehensive example of using them. (I don't need it myself but I think the current answers are not worthy of a bounty.)
yes, this is necessary) but needs to do it while the activity is destroyed to save memory
I got a feeling you are doing something wrong. Why is sending location to remote peer coupled with activity lifecycle? I do not see any sense of doing that. If you want to send location only when you are in foreground you can utilise ActivityLifecycleCallbacks so you can be notified when you went into foreground or background and stop your separate sending worker when you go into background or resume when your activity become front-most one.
As for recent list related question, let me paste this comment by Dianne Hackborn:
what specifically happens when you swipe away a recent task is it: (1) kills any background or empty processes of the application (see http://developer.android.com/guide/topics/fundamentals/processes-and-threads.html#Lifecycle for what this means), and (2) uses the new http://developer.android.com/reference/android/app/Service.html#onTaskRemoved(android.content.Intent) API to tell any services of the application about the task being removed so it can do whatever it thinks is appropriate.
you can find this post here: https://plus.google.com/105051985738280261832/posts/GfwRYCC42uX (I failed to find the way to link directly to the comment on google plus thing).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With