Android: multiple instances of activity running for the same purpose. Bring one to the fore?

I am struggling with my application that runs multiple instances for the same purpose. My main activity is of type A class, and it has startActivity () of two children who have the same type B. Thus, we launched B1 and B2. If B1 and B2 are both paused (by pressing the "Back" button and making sure that the finish () is not called on them, so they are really paused), how can we unambiguously bring either B1 or B2 to the forefront again? I want to launch a new activity B. I want to unambiguously bring B1 or B2 to the fore.

therefore, both B1 and B2 were created as follows ... Intent intent = new Intent (context, B.class); intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); startActivity (intent);

Now I want A to bring B1 (or B2) to the front / foreground, so I use the code below, but how can I distinguish between B1 or B2 when starting an Event? This only leads to the fact that the last instance of B was from above in the foreground.

Intent intent = new Intent (context, B.class); intent.addFlags (Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity (intent);

I tried to store links to B1 and B2 and do something like this, but this also only applies to the last instance of activity class B, which was on top ...

Target Intent = New Intent (B1context, B.class); intent.addFlags (Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); B1context.startActivity (intent);

, B1 B2... = B1.getIntent();//.. startActivity ();// B, .

!

+3
3

. . C, B. - , n B. . 10-20 AndroidManifest.xml , .

, . .

, Android , , . , id Activity .

+1

, . NEW_TASK - "", . , , ( , ..).

, , , , , , . , NEW_TASK - , .. , . , , .

0

:

Intent mIntent1 = new Intent(this, Activity1.class);
mIntent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
Intent mIntent2 = new Intent(this, Activity2.class);
Intent[] list = new Intent[2];
list[0] = mIntent1;
list[1] = mIntent2;
startActivities(list);
0

Source: https://habr.com/ru/post/1774843/


All Articles