I have a list of actions in my application.
If the user is on a home operation, the message “Ask the user to press again to exit” appears.
But if the user goes to the 2nd or 3rd action and returns to home activity again, my code cannot show a toast.
I want that every time a user at a home operation, a toast should appear.
I know there is some kind of error in my logic. Can someone help me please.
This is the code to push back.
@Override
public void onBackPressed() {
i++;
if (i == 1) {
Toast.makeText(HomeActivity.this, "Press back once more to exit.",
Toast.LENGTH_SHORT).show();
} else if(i>1) {
finish();
super.onBackPressed();
}
}
source
share