There are three Activites where B's launch mode is "SingleTask". I'm wondering How to start a new B rather than restarting the old B when using C?
How to ignore the launcheMode of "SingleTask" when starting an Activity?
477 views Asked by gaomode At
2
There are 2 answers
0
On
Use below code in onBack press method of activity
@Override
public void onBackPressed() {
Intent BackpressedIntent = new Intent();
BackpressedIntent .setClass(getApplicationContext(),B.class);
BackpressedIntent .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(BackpressedIntent );
finish();
}
Unfortunately, if Activity B is set in the manifest to use
android:launchMode="singleTask"
, there is no way (that I know of) to override this.However, you could remove this attribute from your manifest and instead use code like this when you wanted the
singleTask
behavior:The end result is that you get
singleTask
behavior when you want it, and you don't get it when you don't want it. You just have to change the strategy.