In my application i have 4 fragments like the follow [A] [A-sub] [B] [B-sub] when the user press back button from [A] or [B] it should exit the app suppose the user press back button from [A-sub] or [B-sub] it should redirect the app to [A] or [B]
I hope you got my problem
i have tried the follow in my main fragment activity but i know its only the solution for exit the app
private boolean _doubleBackToExitPressedOnce = false;
@Override
public void onBackPressed() {
System.out.println("onBackPressed--");
if (_doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this._doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Press again to quit", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
_doubleBackToExitPressedOnce = false;
}
}, 2000);
}