0

I need a notification when an android app is removed from the task manager. I need to perform some cleanup when that happens.

onDestroy(), finalize() or onSaveInstanceState() is not called. I'm guessing they are called when there is a need for more memory.

sr09
  • 720
  • 5
  • 26
  • See this - http://stackoverflow.com/questions/2208912/how-can-i-detect-user-pressing-home-key-in-my-activity – Atul O Holic Mar 05 '14 at 18:41
  • `onPause()` is the way to do it, since it will be called when the user switches to the task manager. There is no way to know when your app is killed. In the need for more memory, your app can be killed without any further callbacks. The safe approach is to save state/cleanup in `onPause()`, then assume that the next callback will be `onCreate()`. This simple approach covers almost everything. Think of Android activities like web pages. What happens if you are on a web page, fill in some data, then click "back" (or close the browser - just like killing your app)? Just the same in Android. – Simon Mar 05 '14 at 18:41
  • What cleanup do you think you need to do, and why? – Chris Stratton Mar 05 '14 at 18:50
  • I constantly append to a file when i play around with the app. When i remove from task manager, i want to delete the file. Not when I press the back key, or not when I move it to background. – sr09 Mar 05 '14 at 19:02
  • 1
    Like I say, there is no way for you to know. Your app will be killed with no callback. – Simon Mar 05 '14 at 22:50

0 Answers0