Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

Why does "Home" button call `onDestroy()` in my Android app?

On the Android dev page, it says pressing the "Home" or "Overview" button does not invoke onDestroy,

but in my app, it keeps calling onDestroy. Are there any clues?

(detail situation below)

I've built a simple app that switches from the main activity to a second activity,

but if I press the "Home" or "Overview" button on the second activity, the onDestroy gets called.

So when I go back to my app again, it shows the main activity, not the second activity.

Is this normal?

Should I save the state if I want to go back to the last activity (not the main activity) after pressing the Home or the Overview button and coming back to my app?

Android dev page that I read:

If a new activity or dialog appears in the foreground, taking focus and completely covering the activity in progress, the covered activity loses focus and enters the Stopped state. The system then, in rapid succession, calls onPause() and onStop().

and

Note: When the user taps the Overview or Home button, the system behaves as if the current activity has been completely covered.

So it is supposed to invoke only onPause and onStop, not onDestroy, isn't it?

question from:https://stackoverflow.com/questions/66058265/why-does-home-button-call-ondestroy-in-my-android-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You have to put the Code in your Question or we can't help you.

Maybe you are calling finish() in MainActivity after you call startActivity(MainActivity.this, SecondActivity.class) ?

Use the edit-function and show us your code then we can help you more.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...