This code works for all API Levels.
public class MyActivity extends Activity { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { moveTaskToBack(true); } return super.onKeyDown(keyCode, event); } }
The below code works for API level 5 or Higher…..
public class MyActivity extends Activity { @Override public void onBackPressed() { moveTaskToBack(true); } }