I'm developing an Android Webview app at the moment. I'm using the following code to exit my app. The problem is that by using this code, I can't return to the previous page anymore so it's not yet what I had in mind.
Goal:
I'd like to show the below toast message only when pressing the back-button on the homepage. When the user is on a different page than the homepage, pressing the back-button should just return to the previous page.
How could I do something like that?
private Boolean exit = false;
@Override
public void onBackPressed() {
if (exit)
this.finish();
else {
Toast.makeText(this, "Press again to close the app.",
Toast.LENGTH_SHORT).show();
exit = true;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
exit = false;
}
}, 3 * 1000);
}
}