I have an application that calls an activity several times from different activitys. So, im trying to implement the "back button" in the action bar for this activity. For doing this im using:
switch (item.getItemId()) { case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; default: return super.onOptionsItemSelected(item); }
and:
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="view.TweetsIndividuoActivity" />
The problem now, is that i cannt set a parent activity to my android manifest, cause, i don't know who is the parent of this activity.
What is the solution ?
Thanks
Declare a Parent Activity You can do this in the app manifest, by setting an android:parentActivityName attribute. The android:parentActivityName attribute was introduced in Android 4.1 (API level 16). To support devices with older versions of Android, define a <meta-data> name-value pair, where the name is "android.
There is several way to remove a activity from the stack or prevent it to be stacked : To remove your activity from the stack , simply call finish() , see here. You can also implement in your manifest the property : android:noHistory="true" which prevent an activity to be stacked.
If the user presses or gestures Back, the current activity is popped from the stack and destroyed. The previous activity in the stack is resumed. When an activity is destroyed, the system does not retain the activity's state.
As per docs -> section android:parentActivityName : The system reads this attribute to determine which activity should be started when the user presses the Up button in the action bar. The system can also use this information to synthesize a back stack of activities with TaskStackBuilder .
It's easier than you think.
switch (item.getItemId()) { case android.R.id.home: finish(); return true; default: return super.onOptionsItemSelected(item); }
Method finish()
will destroy your activity and show the one that started it. That's what you want if I understood you right.
Your current solution is meant for cases when you want go back to the same parent every time e.g. Gmail app does it. When you open email from notification and then press actionbar back button it will not navigate back to HOME screen but it will show you Gmail inbox.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With