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
:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id== android.R.id.home ){
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
Also this solution works for me:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent intent = NavUtils.getParentActivityIntent(this);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
NavUtils.navigateUpTo(this, intent);
return true;
default:
break;
}
return super.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"