Reputation: 794
I want to create a "home" button that will bring the user back to the "Home" in my app from whatever activity they are in at the time. I have overridden the action bar so I won't be able to use one. My problem is that when
Home → A → B
I want to press the home button to return to Home. Originally I had the home button simply finish()
the activity but in this case that will return me to A. Is there a way to do what I'm attempting?
Just to clarify this is an ImageButton
on screen, not the hardware home button on the device.
Upvotes: 1
Views: 91
Reputation: 303
You can simply have your Image Button create an intent to start your home screen activity, assuming this is what you were looking for. within the OnClick of the button, generate an intent, and startActivity(intent)
Upvotes: 0
Reputation: 44571
You can use the Intent-Flag
FLAG_ACTIVITY_CLEAR_TOP
If you don't have many Activities
then you can simply create an onClick
in each that is something like
Intent intent = new Intent(CurrentActivity.this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
this flag will take you back to the "Home" Activity
and clear all others off of the stack
If you have many Activities
then it may be easier to create a base Activity
from which to extend all others and include the home button functionality inside that base Activity
Upvotes: 3