You're on an activity and you press the home button.

Then you long press home menu button, and select the activity you were on, from the 'recent activities' screen.

What method is called when the activity shows again? onResume, onRestart or any other?

有帮助吗?

解决方案

I believe onResume will be called anyways even after pause or stopped.

onRestart may be called if activity has been stopped in the background

The recommendation is to save your data in onPause and rebuild it on onResume with some flags, so flags can tell you if onResume called after onPause/onStopped or Activity is freshly created.

其他提示

Taken from the Android developer website

"... When the user leaves your activity, the system calls onStop() to stop the activity (1). If the user returns while the activity is stopped, the system calls onRestart() (2), quickly followed by onStart() (3) and onResume() (4). Notice that no matter what scenario causes the activity to stop, the system always calls onPause() before calling onStop()..."

Here is the Activity enter image description here

So no Matter what onResume() would get eventually called.

You can download the ActivityDemo which exhibits the Android lifecycle accurately. This should help you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top