I want to call method in ondestroy override method but that override method is not calling android o only. Why it is not calling is there any alternative for that please any one help me to resolve my issue.Thanks in advance.
-
2`onDestroy()` for what? Service, Activity or...? update your question with more information – Sagar Jul 10 '18 at 05:42
-
Are you overriding it in a Fragment? – W3hri Jul 10 '18 at 05:44
-
in Activity after kill my app in android o on Destroy is not calling in remaining version onDestroy is calling@sagar – v teja Jul 10 '18 at 05:45
2 Answers
Given your comment that you are overriding onDestroy() in the activity and killing your app manually:
Please be aware that there it's not guaranteed that the onDestroy() will be called properly. Because of that, you should not perform critical actions there.
See an excerpt from the Documentation:
Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either onPause() or onSaveInstanceState(Bundle), not here. This method is usually implemented to free resources like threads that are associated with an activity, so that a destroyed activity does not leave such things around while the rest of its application is still running. There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away.

- 1,563
- 2
- 18
- 31
Need to work in android o, Could you send your codes?
public void onDestroy() {
...
// Must always call the super method at the end.
super.onDestroy();
}

- 1
-
1
-
Even if you place your code before `super.onDestroy();`, there is no guarantee that it will be called. – HB. Sep 11 '19 at 09:40