Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent onDestroy() always being called with back button

Tags:

android

I appear to have the opposite issue to every other post on the topic I have come across. Others find that onDestroy() is not always called but I find it always and immediately is.

I am checking whether it is called with the following:

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "onDestroy");
}

This log code is triggered immediately after either clicking back or using my actionbar button which just calls the home activity as an intent.

I have looked around but everyone says the lifecycle should look like this: http://developer.android.com/images/activity_lifecycle.png

This behaviour is not limited to a single app; I have tried downloading some example code and adding in the above debugging code only to find the same behaviour. It is also not limited to a single android version; I have tried 2.1 and 2.3 in the emulator and also 4.0.2 on a physical device.

Any ideas of what I might be doing wrong?

like image 719
dhewett Avatar asked Feb 21 '23 09:02

dhewett


1 Answers

pressing back key actually provokes finish() method on your activity, and it causes your activity to be paused->stopped->destroyed

so technically this behavior is functional as expected.

like image 184
waqaslam Avatar answered Mar 03 '23 01:03

waqaslam