I have two avtivities. Let's call them ActivityA
and ActivityB
. ActivityA is marked singleTask
in manifest file.
I can start ActivityB
from ActivityA
using simple startActivity
call (no Intent
flags used). Also I can start ActivityC
from ActivityA
and start ActivityB
from it (also using "simple" Intents
).
ActivityB
has a button which performs this code:
Intent intent = new Intent(ActivityB.this,
ActivityA.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
I also have a widget which can start ActivityA
using this code:
Intent aIntent = new Intent(context, ActivityA.class);
aIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
aIntent, 0);
And also it can start ActivityB
from grid items:
Intent bIntent = new Intent(context, ActivityB.class);
PendingIntent bPendingIntent = TaskStackBuilder.create(context)
.addNextIntent(aIntent).addNextIntent(bIntent )
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
If I start ActivityA
from launcher, start ActivityB
from it (or ActivityA
->ActivityC
->ActivityB
) - I can move back to ActyvityA
(or ActivityC
) using back button or button in ActivityB
(described above) and ActivityA
is not recreated.
That's OK.
The problem is that if I start ActivityB
from widget and use back button or button in ActivityB
(described above) ActivityA
is recreated and becomes single instance in stack.
I want to be able to manage those two activities the way ActivityA
is always the root one and NOT RECREATED if it is already running.