Issue
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.
Solution
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
Answered By - codeMagic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.