Exit from Activity with twice “Back” button click

When we are doing some important operation or work on activity and it may possible that by mistake we pressed “back” button. Then what?? This will simply stop all your important work and you are redirect to previous activity.

To overcome this situation, we can provide a confirmation to the user that you need to press once again to exit from activity. This will give user a great experience in application.

To add this functionality in you application, use following code snippet.

Expatiation

doubleBackToExitPressedOnce” is core of this snippet. When user presses “back” button, value for “doubleBackToExitPressedOnce” is “false” and he will get a message for “Press once again to exit“.

If user presses “back” button one more time, he will redirect to previous activity as “doubleBackToExitPressedOnce” is now “true“.

You may also like to read

APK Analysis : Spotlight on WhatsApp | How to use ... Android Studio includes an APK Analyzer that provides immediate insight into the composition of your APK after the build process is complete. In th...
Android Unique Identification Number Some times, when we are integrate our android application with server, its requirement of server that it can identify every android device uniquely. S...
Customizing TextInputLayout – Part 2 In previous article Customizing TextInputLayout - Part 1, we learnt how to customize TextInputLayout and how to apply hint color to it. Going t...
Create custom Toast in Android Studio In this article we learn how to create Custom Toast in Android Studio. Toast A Toast provides simple feedback in a small popup about an operatio...
Share on Facebook0Share on Google+0Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on Tumblr0Email this to someone
  • nfl coins farming

    With havin so much written content do you ever run into any
    problems of plagorism or copyright violation? My site has
    a lot of completely unique content I’ve either created myself or outsourced but it looks like a lot of it is popping it up all over the internet without
    my agreement. Do you know any solutions to help protect against content from being
    stolen? I’d truly appreciate it.

    • Chintan Rathod

      Hi, I saw “Creative Commons” licence under each blog of “http://blog.stylingandroid.com/”. That blog is very popular for Android tutorials. So I guess you can also use the same for your blog. :)

  • raulsanchez

    What’s Taking place I am new to this, I stumbled upon this I’ve discovered
    It positively useful and it has aided me out loads.
    I’m hoping to contribute & help different users like its aided me.
    Good job.

  • fifa 15 apk data

    Hi! Do you know if they make any plugins to help with SEO?
    I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains.
    If you know of any please share. Many thanks!

    • Chintan Rathod

      Currently I am using WordPress SEO by Yoast. You can also use it. It is very helpful.