some applications (like for example the Dolphin HD Browser) implement the following feature:
Pressing “Back” jumps back in the back stack. When the initial view/activity/fragment is shown and you press “Back”, a Toast appears saying “Press Back again to quit” or something similar.
How could I implement this feature?
Catch the back-button event like so:
Now create a flag so your application won’t close the first time it fires.
Finally end your activity by calling
finish();on your activity.For quickly showing Toasts use this:
Provided that you’re launching this code from your activity class. If not, try to get the context of your activity instead of using
this.