-1

i have three Activities A , B and C ; The Activity C above the activity B and B above A . class A :

button.setonclicklistener...
.
.
.{
startactivity(A.this , B.class() )  ;
}
.
.
.}

class B :

button.setonclicklistener...
.
.
.{
startactivity(B.this , C.class() )  ;
}
.
.
.}

now I'm in Activity C , how delete (finish)the Activity C , and B with a Button From activity C :

button.setonclicklistener...
.
.
.{
Finish();//activity C 
Finish();//activity B 

}
.
.
.}
Redouane
  • 1
  • 1
  • 2
    If you have to do something like this you should probably considering combining B and C into one `Activity` with two `Fragment`s and just switching between the `Fragment`s instead of opening a new `Activity`. Having to finish multiple `Activity`s is in most cases a sign of messed up navigation in your app. – Xaver Kapeller Jan 30 '16 at 00:26

2 Answers2

1

Start Activity C with startActivityForResult. In ActivityB when onActivityResult is called, call finish.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
0

Start Activity A with flag CLEAR_TOP.

Intent intent = new Intent(ActivityC.this, ActivityA.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // Removes other Activities from stack
startActivity(intent);

Reference:- 1. CLEAR_TOP_REFERENCE

  1. Answer reference
Community
  • 1
  • 1
AAnkit
  • 27,299
  • 12
  • 60
  • 71
  • The one problem with this is that the intent of activity A will be overwritten with the new Intent. This can be a problem if you're depending on values in it – Gabe Sechan Jan 30 '16 at 00:26
  • @GabeSechan it will be weird scenario to have values in Activity A and opening B and C. Anyways that can be handled by saving values in preferences in onPause and loading them back in onResume. No? – AAnkit Jan 30 '16 at 00:29
  • No. The clear top flag erases the original intent. And it's not unusual to have parameters in A that then opens another activity. That said, if A has no parameters clear top is a good solution – Gabe Sechan Jan 30 '16 at 00:55
  • @GabeSechan I see where you are going. Totally agree with your point now. Thanks for sharing your views. – AAnkit Jan 30 '16 at 06:20