How to minimize app on pressing back button or home button in android

193 Views Asked by At

I want to show app in particular size on pressing back button or home button.

1

There are 1 best solutions below

0
WebDesk Solution On

The code below demonstrates how to emulate the home button press when the user presses the back button, and in my opinion, treating the back event as a home event is necessary.

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