0

Description:

I have an activity (Activity A) with a button that changes to another activity (Activity B) which has another 3 buttons. Button A goes to Fragment A, Button B goes to Fragment B and Button C goes to Fragment C. I am overriding onBackPressed method:

Question:

How can I manage onBackPressed method in order you can´t go back to Activity A (which is a login activity) but can go back, for example, from fragment C to B?

Edit:

I am using the following script to go back between fragments:

getActivity().onBackPressed();
Zain
  • 37,492
  • 7
  • 60
  • 84
Tomas M
  • 287
  • 4
  • 16
  • Hello thomas, all you need is to manage fragmentbackstack. Checkout link below: https://stackoverflow.com/questions/14275627/how-to-go-back-to-previous-fragment-on-pressing-manually-back-button-of-individu – Mohammed Junaid Feb 28 '20 at 16:41

1 Answers1

0

You can remove an activity from the history stack. You can achieve this by setting the android:noHistory attribute to "true" on Activity A.

<activity
    android:name=".Activity_A"
    android:noHistory="true" />

but if this is a particular case you can launch your activity A from other Activity D in this way

//From activity D
val intent = Intent(this, Activity_A.class)
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
startActivity(intent)

Other way to remove Activity_A from stack is calling finish() after launch your Activity B

Juan Fraga
  • 434
  • 3
  • 9