onBackPressed() method not triggered in AppCompatActivity

前端 未结 6 1051
囚心锁ツ
囚心锁ツ 2021-02-13 23:26

AppCompatActivity onBackPressed() method fails to trigger in my activity.

I see the back arrow button and get the animation when pressing it, but nothing else happens. a

6条回答
  •  天命终不由人
    2021-02-14 00:14

    In your manifest file define the following inside your activity tag:

    
    

    After that in your activity:

    @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            switch (item.getItemId()) {
            case android.R.id.home:
                NavUtils.navigateUpFromSameTask(this);
                return true;
            default:
                return super.onOptionsItemSelected(item);
            }
        }
    

提交回复
热议问题