Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

android - Launching an activity at its current state

I am trying to make a task switcher and I succeeded in it. My only problem is that when I launch activities, they are relaunched as they were new activities ( for instance, I am writing an email, I press home and go into my activity,launch email, and then the app launch the email bout goes back to the inbox and the email is lost) So that's not true multitasking.

Here are my steps:

1) getting all the running apps:

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

2) getting the intent:

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

3) Launching the application when 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? Should I do something different to get it?

Thank a lot for any answer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

When creating the Intents you should not use Intent.FLAG_ACTIVITY_NEW_TASK, you should use FLAG_ACTIVITY_REORDER_TO_FRONT.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...