tags:

views:

246

answers:

2

Hello,

I am trying to make a task switcher and i succed 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 at 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.

+1  A: 

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

Lucas S.
Thank a lot.Do you think the: FLAG_ACTIVITY_RESET_TASK_IF_NEEDED is a good idea?The doc says:If set, and this activity is either being started in a new task or bringing to the top an existing task, then it will be launched as the front door of the task.Is that a good idea in your mind to add such a flag?
Profete162
A: 

Sorry if I made mistakes in my explanation, I am quite a "noob" and just tell here my experience to improve the result of people searching for the same answer than me.

In fact, I had to Use intent.setFlag(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_REORDER_TO_FRONT) for the best result. Replacing was not the best Idea.

Not using FLAG_ACTIVITY_NEW_TASK make the email application launch when I wanted to launch my own application. Because email was "linked" with the same task than my Application.

But Lucas, I keep your answer as the best.

Profete162