Dealing with phone's back button: Back button on home activity always to cause app exit


Let's say I have 4 activities in my app:<br /> A (main activity)<br /> B<br /> C<br /> D

I would like that pressing back in Activity A always produce application exit. In my case if activity flow goes like this A > B > C > A, then if I push back button, I will go to activity C. I want, at that moment, my app to exit.

I assume, app should somehow delete activity history when main activity is active.<br /> How is this to be done?



When you launch your home activity do so with the clear top flag set. This causes the back stack to be cleared.

Intent intent = new Intent(this, HomeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);


If you want the above behaviour then use the <a href="http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP" rel="nofollow">FLAG_ACTIVITY_CLEAR_TOP</a> to launch A. This will clear the all the activities above A


  • Cannot convert a char value to money. The char value has incorrect syntax
  • Is there a chance to get -splash: work for SWT applications that require -XstartOnFirstThread?
  • how to read a file in prolog?
  • include dlls in visual studio c++ 2008
  • Is there any way to call saveCurrentTurnWithMatchData without sending a push notification?
  • Angular Bootstrap Carousel Slide Transition not working correctly
  • Streaming screenshots over WebRTC as a video stream from iOS
  • Runtime.exec() gives Error: Could not find or load main class
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • jQuery: add elements until a particular height is reached
  • quiver not drawing arrows just lots of blue, matlab
  • R Split data.frame using a column that represents and on/off switch
  • Ubuntu and bcrypt
  • Combining two different ActiveRecord collections into one
  • Silverlight DependencyProperty.SetCurrentValue Equivalent
  • Using JRuby with Rails 3.2
  • Code in Job's Script Block after Start-Process Does not Execute
  • How to use carriage return with multiple line?
  • Android fill_parent issue
  • Adding a button at the bottom of a table view
  • Getting last autonumber in access
  • Obtain ObjectIdHex value from mgo query
  • output of program is not same as passed argument
  • How to make Safari send if-modified-since header?
  • jquery mobile loadPage not working
  • Delete MySQLi record without showing the id in the URL
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • Akka Routing: Reply's send to router ends up as dead letters
  • GridView Sorting works once only
  • How to pass list parameters for each object using Spring MVC?
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • unknown Exception android
  • JaxB to read class hierarchy
  • Checking variable from a different class in C#
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • How to push additional view controllers onto NavigationController but keep the TabBar?