wasnt really sure what words to query in google, so im just going to ask this question.
What happens to an activity when i start another activity?
Lets say I am currently on activity A, then from a, i called a function to startService a new intent that opens activity B. What happens to the lifecycle of A? is it destroyed? stopped?
Subquestion. If the activity is paused, how do i call/open it back from the newly started activity?
If you call startActivity() for an Activity with default launch mode(i.e, you didn't mention any launch mode in either in manifest or in Intent) a new instance of the activity is created. For example, A launched B and again B launched A then Activity stack would be A - B - A.
When a new Activity is started on top of the current one or when a user hits the Home key, the activity is brought to Stopped state. The activity in this state is invisible, but it is not destroyed. Android Runtime may kill such an Activity in case of resource crunch.
Start the Second Activity To start an activity, call startActivity() and pass it your Intent . The system receives this call and starts an instance of the Activity specified by the Intent .
We can send the data using the putExtra() method from one activity and get the data from the second activity using the getStringExtra() method.
Activity A is paused, then stopped - both the onPause()
& onStop()
methods are called, but onDestroy()
is not called. The Activity still remains in the back stack.
Quoting the Android documentation:
Activity Lifecycle
Activities in the system are managed as an activity stack. When a new activity is started, it is placed on the top of the stack and becomes the running activity -- the previous activity always remains below it in the stack, and will not come to the foreground again until the new activity exits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With