I am currently using this in my MainActivity for back press twice to exit from the pp. It works fine but the problem is after second press to exit from app, the app exits coorectly with a black screen which is not convinient for user. How do I overcome this problem?
@Override
public void onBackPressed() {
if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
getSupportFragmentManager().popBackStack();
navigationView.getMenu().getItem(0).setChecked(true); //set the background to the correct place
} else if (!doubleBackToExitPressedOnce) {
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, R.string.press_twice_to_exit, Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
} else {
super.onBackPressed();
System.exit(0);
}
}