Delete old activity instance when starting a new activity
It seems that deleting the activity is not as easy as I would have imagined therefore not a complete answer but I'm going to go with using FLAG_ACTIVITY_REORDER_TO_FRONT. This will not kill the existing activity but instead move it to top of stack.
Intent intent = new Intent(ctx, Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
This will allow for the activity navigation outlined above.
I'm still interested if someone knows of a means to clear the actual activity.
I am able to do that by overriding onNewIntent
@Override
protected void onNewIntent(Intent intent) {
Bundle extras = intent.getExtras();
Intent msgIntent = new Intent(this, MyActivity.class);
msgIntent.putExtras(extras);
startActivity(msgIntent);
finish();
return;
super.onNewIntent(intent);
}
make activity single task
<activity
android:name=".MyActivity"
android:launchMode="singleTask" >
</activity>
You could use the Intent
flags to remove the earlier task. Hopefully this helps.
Intent intent = new Intent(this, Activity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
This flag will cause any existing task that would be associated with the activity to be cleared before the activity is started. That is, the activity becomes the new root of an otherwise empty task, and any old activities are finished.