You need to start the Activity-2
as a new task.
When you start the Activity-2
from the service
, do this
Intent intent = new Intent(this,Activity2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent)
Also, make sure the Activity-1
and Activity-2
has different task Affinity
, by default activities in same package will have same 'taskAffinityas its package name. You can set a differnt 'taskAffinity' for
Actiivty-2` , so that it will be launched in different task.
See here http://developer.android.com/guide/components/tasks-and-back-stack.html The affinity comes into play in two circumstances:
When the intent that launches an activity contains the FLAG_ACTIVITY_NEW_TASK
flag.
A new activity is, by default, launched into the task of the activity that called startActivity(). It's pushed onto the same back stack
as the caller. However, if the intent passed to startActivity() contains the FLAG_ACTIVITY_NEW_TASK
flag, the system looks for a different task to house the new activity. Often, it's a new task. However, it doesn't have to be. If there's already an existing task with the same affinity as the new activity, the activity is launched into that task. If not, it begins a new task
.