Hello!

I study Android, I write code in AndroidStudio. I decided to make an application that can collapse when I press the "Back" button, or whatever it is. I did not find the answer to such a banal question, no one asked here either. Is it possible to minimize the application program?

Thanks in advance for the answers)

  • Those. to minimize the back button like the home button? But why? - gcoder
  • In order to learn. - Alerr

2 answers 2

No need to invent applications. There's no such thing. Once your application has gone to the background, the system can nail it at any time.

If you want the application to “end” by clicking the back button - just make sure that the activation stack is empty. The system will do everything for you.

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

    such code should help. Paste this method into your activity class.