Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happens when an android activity starts another activity

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?

like image 341
ibaguio Avatar asked Oct 02 '12 11:10

ibaguio


People also ask

What happens when an application calls startActivity for an activity that already has an instance running?

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 activity?

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.

How do you call one activity from another activity?

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 .

How can call one activity method from another activity in Android?

We can send the data using the putExtra() method from one activity and get the data from the second activity using the getStringExtra() method.


1 Answers

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.

like image 136
keyser Avatar answered Oct 06 '22 15:10

keyser