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

Using Facebook’s Shimmer effect in Android &... In this tutorial, you will learn about how to implement "Shimmer effect" developed by Facebook for Android. Download Source Code
ProGuard Secure your APK from Reverse Engineering ... Following are words from http://proguard.sourceforge.net who are inventor of it. ProGuard is a free Java class file shrinker, optimizer, obfuscator...
NFC Mifare UID (Card Serial Number) reverse issue ... If you are using NFC (Near Field Communication) Mifare in your application, you should be careful while using NFC Mifare UID  (Unique IDentification ...
Develop apps faster using Data Binding – Par... Google has been pushing updates to existing tools and making the life of android developers easier. They also have been releasing new libraries and AP...
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.