Running an activity in its current state

I am trying to make a task switch, and I succeeded. My only problem is that when I start actions, they restart because they are new actions (for example, I write an email, I click on the house and go into my activity, I start the email, and then the application starts by email to your inbox and email will be lost). So not true multitasking.

Here are my steps:

1) getting all running applications:

List<ActivityManager.RunningTaskInfo> allTasks = activityManager.getRunningTasks(30);

2) receipt of intent:

for (ActivityManager.RunningTaskInfo aTask : allTasks) {
        Intent i = new Intent(Intent.ACTION_MAIN);
        i.setComponent(aTask.baseActivity);
(...)

3) Launch the application by clicking on the button:

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED).addCategory(Intent.CATEGORY_LAUNCHER);
    monthis.startActivity(intent);

`

What is wrong with this code? Do I have to do something else to get it?

Thanks so much for any answer.

+3
3

Intent.FLAG_ACTIVITY_NEW_TASK, FLAG_ACTIVITY_REORDER_TO_FRONT.

+3

, , "" , , , .

, .setFlag(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_REORDER_TO_FRONT) . .

FLAG_ACTIVITY_NEW_TASK, , . "" , .

, .

0

, . , ,

, activity1 activity2, activity1 activity2 ( activity2) 1, Activity1. 2, 2 , activity2.

, :

<activity android:name=".activity2"
          android:alwaysRetainTaskState="True"
          android:launchMode="singleInstance">
</activity>

1 :

Intent intent=new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.setClassName(this,"com.mainscreen.activity2");
startActivity(intent);

Activity2 click :

Intent intent=new Intent();
intent.setClassName(this,"com.mainscreen.activity1");
startActivity(intent);

Now, what happens is that any changes we make to Activity2 will not be lost, and we can view activity2 in the same state as before.

I believe this is the answer, and it works great for me. Correct me if I am wrong.

0
source

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


All Articles