ActionBar 'up' button destroys parent activity, 'back' does not

谁说我不能喝 提交于 2019-11-28 17:10:46

You can override what the actionbar up button should do like:

public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

case android.R.id.home:
    onBackPressed();
    return true;
}

return super.onOptionsItemSelected(item);
}

And recreate the back button effect.

vikki_logs

In the android manifest.xml adding the following attribute for the parent activity tag worked for me.

android:launchMode="singleTop"

Reference : http://developer.android.com/guide/topics/manifest/activity-element.html

Refer the similar question: How can I return to a parent activity correctly?

Jolson Da Costa

when you specify parent activity in manifest then it gets restarted when you click on up Navigation button in action bar.

check this i already answered this question

https://stackoverflow.com/a/32401235/3479012

you need to override up nevigation button in actionbar by accessing it by android.R.id.home in onOptionsItemSelected and do finish top activity.

It looks like your parent activity isn't setup properly in your manifest. Add this inside your ShowInstanceActivity activity tag:

<meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".agenda.ListInstancesActivity" />

So, your final activity tag should look like:

<activity
  android:name=".agenda.ShowInstanceActivity"
  android:label="@string/show_instance_activity_title"
  android:parentActivityName=".agenda.ListInstancesActivity">
  <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".agenda.ListInstancesActivity" />
</activity>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!