Akshay J Akshay J - 2 months ago 16
Android Question

Restart app from first activity

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));

Answer

With that launchMode you can add the flag: FLAG_ACTIVITY_CLEAR_TOP to your intent to start the activity.