I have gone through android docs on FLAGS and Affinity (Link) and tried different combinations that I thought would help achieve my requirement but it seems that I'm missing something.
I need to initiate activityA
from from BroadcastReceiver
and then finish activityA
and start activityB
. so when the user presses back it wont go back to activityA
; when user presses back
on activityB
it will stop the activityB
and it will go to back stack
however when the user opens app back from task manager
it will start up from activityA
.
Note: this does not happen when there is another activity of the app in the background.(only happens when the app is entirely force closed/killed).
also when user presses home button
in activityB
it behaves as intended.
I use the following code to lunch activityA
from BroadcastReceiver
.
Intent intent = new Intent(context, ActivityA.class);
intent.putExtra(EXTRA_TAG, new Gson().toJson(remoteMessage));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
I use the following code to lunch activityB
from ActivityA
.
Intent intent = new Intent(this, ActivityB.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(intent);
finish();
Is there a different FLAG
that I need to use to achieve this requirement?