Android Activity

I have 5 actions and the thread is like this

1 β†’ 2 β†’ 3 β†’ 4 β†’ 5

in step 5, after pressing the back button, is it possible to return to step 2 or 3 without completing any operation? Currently, I am only getting to the fourth.

+4
source share
4 answers

If you want to get 2 or 3 u want to write the code on the back key

@Override public boolean onKeyDown(int i, KeyEvent event) { if (i == KeyEvent.KEYCODE_BACK) { Intent i=new Intent(getbaseapplicationcontext(),activity2.class) startActivity(i) return true; } return super.onKeyDown(i, event); } 

And one more way -

u want to complete the work, whatever you want How you need Activity4 here

+1
source

There's something like an ActivityHistory . I'm not very sure about the exact keyword, but there is something similar. You can go through it.

Maybe this link helps!

+2
source

One solution to your problem could be simply overriding the hard back button and then starting any activity that you want to start. But overriding the default behavior is not recommended. Check back for any request.

0
source

When a new action begins, it is pushed onto the back stack and takes user focus. The back stack corresponds to the main mechanism of the β€œlast time for the first time” stack, therefore, when the user performs the current activity and presses the β€œBack” button, it is ejected from the stack (and destroyed), and the previous action is resumed. The back button is pressed.

 @Override public boolean onKeyDown(int i, KeyEvent event) { if (i == KeyEvent.KEYCODE_BACK) { Intent intent = new Intent( YourActivity.this, New Activity.class ); intent.setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP ); startActivity( intent ); return true; } return super.onKeyDown(i, event); } 
0
source

Source: https://habr.com/ru/post/1337431/


All Articles