A simple Android application consists of two Activity components. The first, MainActivity, contains a String and an Integer. It also displays a button that, when pressed, launches SecondActivity via an explicit Intent. The user launches the application, then presses the button, and then presses the back button. i. Describe the life-cycle calls that these two Activities would receive, and in what order they would receive them. You should illustrate your answer with a diagram of the Activity stack as it changes over time.
时间: 2023-11-28 16:47:39 浏览: 74
Activity测试指导(英译中)
The lifecycle calls for the two activities would be as follows:
1. MainActivity: onCreate() -> onStart() -> onResume()
2. SecondActivity: onCreate() -> onStart() -> onResume()
3. MainActivity: onPause() -> onStop()
4. SecondActivity: onPause() -> onStop() -> onDestroy()
5. MainActivity: onRestart() -> onStart() -> onResume()
6. MainActivity: onPause() -> onStop() -> onDestroy()
The diagram of the Activity stack as it changes over time would look like this:
```
| |
| MainActivity | // created, started, and resumed
| |
|---------------|
| |
| SecondActivity | // created, started, and resumed
| |
|---------------|
| |
| MainActivity | // paused and stopped
| |
|---------------|
| |
| SecondActivity | // paused, stopped, and destroyed
| |
|---------------|
| |
| MainActivity | // restarted, started, and resumed
| |
|---------------|
| |
| MainActivity | // paused, stopped, and destroyed
| |
|---------------|
```
阅读全文