Sandeep Sharma
Sandeep Sharma

Reputation: 1885

Forcibly closing Activity but onDestroy does not get called

I have some resources to clean up(at the server side) when user closes the app by swiping the app from all open apps or pressing back button. My onDestroy is not being called in these above cases.So my question is

Which callback method is needed for the above scenarios and Why?

Upvotes: 1

Views: 710

Answers (1)

Youngjae
Youngjae

Reputation: 25050

It would be good to place in onPause method as onDestroy is not guaranteed to be called always especially in your swipe-to-close case. And, onStop also not guaranteed to be called in low memory situation.

Official document about onDestroy also says as below;

Note: do not count on this method being called as a place for saving data!

Upvotes: 1

Related Questions