Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is onDestroy() called after onResume() when using back-button

Tags:

android

When I start my android-activity first onCreate() is called, then onResume().

When I then press the back-button to return to the home-screen and tap the app-icon again, first onCreate() is called, then onResume() and then onDestroy().

My app is still active then, but doing some action result in error since onDestroy() sets a few members to null.

Why is that?

Update: When I wait 30 seconds after pressing back everything works fine. I'm not doing anything heavy in onDestroy except setting a few variables to null and .interrupt()ing a background-thread.

like image 319
Fabian Zeindl Avatar asked Oct 22 '22 09:10

Fabian Zeindl


1 Answers

Figured this out by myself. My understanding of what an Activity is was flawed. Of course Android calls onDestroy() on the old Activity instance, which can happen several seconds after the new one has been constructed.

like image 70
Fabian Zeindl Avatar answered Nov 15 '22 05:11

Fabian Zeindl