This is quick solution. Best practice will be use Service.
public class TestActivity extends Activity {
//...
// Working for all API levels
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(true);
}
return super.onKeyDown(keyCode, event);
}
// Alternative variant for API 5 and higher
@Override
public void onBackPressed() {
moveTaskToBack(true);
}
}
1 Comment
I am using Fragment, instead of going back to the first fragment, pressing back button close the application. Any help will be great. thank you.