开发者

How to catch event of coming back to an activity after hitting back

开发者 https://www.devze.com 2023-03-18 06:43 出处:网络
I have a main screen for my applicat开发者_运维百科ion which then leads to different screens, from each of those hitting back takes you back to the main screen. I want to do some stuff every time a us

I have a main screen for my applicat开发者_运维百科ion which then leads to different screens, from each of those hitting back takes you back to the main screen. I want to do some stuff every time a user is "coming back" to the main screen, How do I catch this kind of event???


Use onResume() method in your main activity or Use startActivityForResult method in your activity by overriding the keyDown method in sub activities,it may help you


you cand try this:

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


You could 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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号