How to catch the event of a return to activity after a strike

I have a main screen for my application, which then leads to different screens, and each of these strokes returns you to the main screen. I want to do some things every time the user "returns" to the main screen. How can I catch this kind of event?

+6
source share
3 answers

Use the onResume () method in your main action or use the startActivityForResult method in your activity, overriding the keyDown method in routines, it can help you

+8
source

you will try this:

@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { //your stuff goes here } return super.onKeyDown(keyCode, event); } 
0
source

You can do something like:

 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { // Do your stuff return true; } return super.onKeyDown(keyCode, event); } 
-1
source

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


All Articles