Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - start multiple activities

is it possible to start multiple activities at once? I mean, from main create 3 activities in some order and just the last will be visible? Up to now, I was able to create only one activity.

Thanks

like image 643
Waypoint Avatar asked Oct 07 '11 07:10

Waypoint


People also ask

How do you create multiple activities?

STEP-1: Create new project and your project screen looks like given below. STEP-2: You will have xml and activity java file, path of both file given below. STEP-3: Open your xml file and add the Button because after clicking this button we will move to second activity as shown below. Add TextView for Message.

How do I start an app from another activity?

To allow other apps to start your activity in this way, you need to add an <intent-filter> element in your manifest file for the corresponding <activity> element.


2 Answers

You might need something like this in order to launch deep into the app after the user has clicked a notification in order to display some newly added content, for example.

Intent i = new Intent(this, A.class); i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(i);  Intent j = new Intent(this, B.class); j.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(j);  Intent k = new Intent(this, C.class); startActivity(k); 

In this way you can start activities A, B and C at the same time and suppress transitions to activities A and B. You get a single transition from your current activity to activity C. I strongly suggest that you log the Activity lifecycle method calls (onCreate etc.) to LogCat, for example. It helps a lot in understanding the order of events.

like image 119
Raginmari Avatar answered Sep 20 '22 15:09

Raginmari


This can be a common thing to do in response to deep linking or other use cases where you, basically, need to synthetically rebuild the Task (and all the activities it should contain). Sometimes, just specifying parents in the manifest isn't enough.

Take a look at TaskStackBuilder. One common example:

TaskStackBuilder.create( context )         .addNextIntent( intentOnBottom )         // use this method if you want "intentOnTop" to have it's parent chain of activities added to the stack. Otherwise, more "addNextIntent" calls will do.         .addNextIntentWithParentStack( intentOnTop )         .startActivities(); 
like image 33
gMale Avatar answered Sep 19 '22 15:09

gMale