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

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...
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 ...
RecyclerView in Android Studio – Part 1 What is RecyclerView? RecyclerView is advanced version of ListView. It is designed to work with large scale of data with better performance and mem...
DevFestAhm – GDGAhmedabad 2015 – Aweso... Google Developer Group is Open for all including students, newbies, developers and anyone for all who are interested in Google technologies. It is Guj...
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.