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

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...
Customizing TextInputLayout – Part 1 In previous article TextInputLayout – Material Design Support library Tutorial, we learn what is TextInputLayout and what is functionality of it. How ...
Using Firebase Crash Reporting in Android Firebase is a cloud service provider which gives you the tools and infrastructure need to build better apps and grow successful businesses. There a...
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...
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.