Reputation: 5458
In my app I have the following sequence:
A->B->C
In C
, there is a button which upon pressing should take me straight back to A
. The problem is that after it goes back to A
, upon pressing back it takes me to C
then B
then A
and then finally exists.
What I want is that when the app goes from C
to A
, pressing back should exit the program (and not take me back to C
)
Following code in A
does not work:
android:clearTaskOnLaunch="true"
android:launchMode="singleTask"
Code to go back to A
:startActivity(new Intent(trip.this, login.class));
Upvotes: 0
Views: 295
Reputation: 12803
What I want is that when the app goes from C to A, pressing back should exit the program (and not take me back to C)
Add the following code in your Activity A.
public void onBackPressed(){
Intent a = new Intent(Intent.ACTION_MAIN);
a.addCategory(Intent.CATEGORY_HOME);
a.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(a);
}
Remove these two lines too. I don't think you need them.
android:clearTaskOnLaunch="true"
android:launchMode="singleTask"
Upvotes: 1
Reputation: 5312
With that launchMode
you can add the flag: FLAG_ACTIVITY_CLEAR_TOP
to your intent
to start the activity.
Upvotes: 1
Reputation: 13865
Upon pressing the button at C, you could finish()
the Activities C and B.
activityC.finish();
activityB.finish();
Upvotes: 0