Up Button Calls Ondestroy Of Parent Activity
Right off the top, I want to clarify something: The button that I am struggling with is NOT the back button. I am referring to the up/home button in the ActionBar / Toolbar at the
Solution 1:
I don't know why default up button implementation creates a new activity but a working solution for me is to override onOptionsItemSelected
:
@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {
intid= item.getItemId();
if(id== android.R.id.home ){
onBackPressed();
returntrue;
}
returnsuper.onOptionsItemSelected(item);
}
Also this solution works for me:
@OverridepublicbooleanonOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intentintent= NavUtils.getParentActivityIntent(this);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
NavUtils.navigateUpTo(this, intent);
returntrue;
default:
break;
}
returnsuper.onOptionsItemSelected(item);
}
Solution 2:
I had this problem too, and after a little more digging found the correct solution is to make a change in the manifest to add the following to your parent activity:
android:launchMode="singleTop"
Details are explained here.
Post a Comment for "Up Button Calls Ondestroy Of Parent Activity"