I have many activities.
A is list activity.
B is form activity. And generated dynamically. I open this activity two time in a row.
C is result activity.
A -> B -> B like simple push new activity. if result is success I want to clear all forms when I push C.
A -> B -> B -> C ==> A -> C.
if result is failed when Im in C activity, it can be return different activities like above.
A -> B or A -> B -> B
I use cleartop when I push C but it clear all activities how can I save A activity's state.
How can I manage activities like fragments.
* When I back from second B, first B should open *
You can achieve it by following below steps:
android:launchMode="singleTask" of ActivityA in AndroidManifest.xml file. Set onNewIntent method in ActivityA like below:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Bundle mBundle = intent.getExtras();
if(mBundle!=null){
String launchActivity = mBundle.getString("activityName");
switch (launchActivity){
case "ActivityD": // This is Activity Name Here it is ActivityD.class
startActivity(new Intent(ActivityA.this, ActivityD.class));
break;
}
}
}
Now Start ActivityA from ActivityC like below.
startActivity(new Intent(ActivityC.this, ActivityA.class).putExtra("activityName", ActivityD.class.getSimpleName()));
It will call onNewIntent method of ActivityA and will match the argument and launch ActivityD from ActivityA. So your ActivityA will remain in stack and ActivityD will be added in stack on Top.
ActivityD when you start ActivityB from ActivityD.Regarding ActivityLaunchMode please refer this link
Hope it will work for you!
On Activity A you cant goto Activity B using this
startActivity(new Intent(Activity_A.this, Activity_B.classs));
From B to C
startActivity(new Intent(Activity_B.this, Activity_C.classs));
finish();
From C to D
startActivity(new Intent(Activity_C.this, Activity_D.classs));
finish();
From D to A
finish();
It will close Activity_D and Resume() Activity_A
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With