I need to minimize the android application on back button click

后端 未结 3 658
花落未央
花落未央 2021-02-05 05:10

I need to minimize the application when back button is pressed.

I use following code to catch hardware back button click event


help me with the code of min

3条回答
  •  -上瘾入骨i
    2021-02-05 06:13

    I think that you need to treat back event as home event. The code below is how I emulate home pressed when User press back button:

     public void minimizeApp() {
        Intent startMain = new Intent(Intent.ACTION_MAIN);
        startMain.addCategory(Intent.CATEGORY_HOME);
        startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(startMain);
    }
    

提交回复
热议问题