Override back button to act like home button

后端 未结 10 589
小鲜肉
小鲜肉 2020-11-22 08:38

On pressing the back button, I\'d like my application to go into the stopped state, rather than the destroyed state.

In the Android docs it states:

10条回答
  •  不思量自难忘°
    2020-11-22 09:14

    Use the following code:

    public void onBackPressed() {    
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_HOME);
        startActivity(intent);
    }
    

提交回复
热议问题