0

In my application I have a requrement like, If I press backkey application should not exit(as i have only one activity in my app) instead it should minimize the app as like its happening with the home key press. Any help is appreciated..

  • 1
    I don't know about the feasibility of this, but I believe this is NOT a good practice. Users expect an app to be closed when they press the Back button. What is the point of leaving your app running in the background ? – Sébastien Jul 12 '12 at 08:29
  • That's a good practice if OP wants to save app state. –  Jul 12 '12 at 08:32

2 Answers2

4

// Add this line inside back pressed.

@Override
public void onBackPressed()
{
   moveTaskToBack(true);

}
Daud Arfin
  • 2,469
  • 1
  • 17
  • 35
1

You can probably just save whatever you need in Activity.onSaveInstanceState() and restore the saved info in Activity.onRestoreInstanceState as in this example Saving Android Activity state using Save Instance State

Community
  • 1
  • 1
Alexander Kulyakhtin
  • 47,110
  • 36
  • 104
  • 156