Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open android activity in new task without using android:launchMode="singleTask"

I've created a browser application with main activity which response to the following intents:

 <intent-filter> 
       <data android:scheme="http"/>
       <data android:scheme="https"/>
       <category android:name="android.intent.category.DEFAULT"/>
       <category android:name="android.intent.category.BROWSABLE"/>
       <action android:name="android.intent.action.VIEW"/>
 </intent-filter>

On url click from other task (gmail, sms) if i choose my application, the activity is open in the same task as the calling task. When I choose different browser (Mozila firefox, chrome, dolphine) they are opening in different task.

Looking on other browsers manifest, I see that no one using android:launchMode="singleTask".

I don't want to use single task flag since it is not recommended by google and also makes me other prolems.

I tried to understand how does other browsers do it but didn't figure it out.

any ideas? is there other way to open my activity in different task without using singleTask flag?

like image 535
user3398598 Avatar asked May 26 '14 07:05

user3398598


1 Answers

You can check in onCreate if the activity is running in a single task. If not just finish() it and create it again with using FLAG_ACTIVITY_NEW_TASK

This may help you

   ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

    for (RunningTaskInfo task : tasks) {
        if (ctx.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName())) 
          // check if it's the only one activity or whatever                               
    }
like image 82
Emanuel S Avatar answered Oct 20 '22 21:10

Emanuel S