public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case Resource.Id.home: { var upIntent = NavUtils.GetParentActivityIntent(this); if (NavUtils.ShouldUpRecreateTask(this, upIntent)) { // This activity is NOT part of this app's task, so create a new task // when navigating up, with a synthesized back stack. Android.Support.V4.App.TaskStackBuilder.Create(this). AddNextIntentWithParentStack(upIntent).StartActivities(); } else { // This activity is part of this app's task, so simply // navigate up to the logical parent activity. NavUtils.NavigateUpTo(this, upIntent); } } return(true); } return(base.OnOptionsItemSelected(item)); }
public override bool OnOptionsItemSelected(Android.Views.IMenuItem item) { if (item.ItemId == Android.Resource.Id.Home) { // This is called when the Home (Up) button is pressed in the action bar. // Create a simple intent that starts the hierarchical parent activity and // use NavUtils in the Support Package to ensure proper handling of Up. var upIntent = new Intent(this, typeof(MainActivity)); if (NavUtils.ShouldUpRecreateTask(this, upIntent)) { // This activity is not part of the application's task, so create a new task // with a synthesized back stack. TaskStackBuilder.Create(this) // If there are ancestor activities, they should be added here. .AddNextIntent(upIntent) .StartActivities(); this.Finish(); } else { // This activity is part of the application's task, so simply // navigate up to the hierarchical parent activity. NavUtils.NavigateUpTo(this, upIntent); } return(true); } return(base.OnOptionsItemSelected(item)); }
public static void NavigateUp(Activity activity, Bundle extras = null) { Intent upIntent = NavUtils.GetParentActivityIntent(activity); if (upIntent != null) { if (extras != null) { upIntent.PutExtras(extras); } if (NavUtils.ShouldUpRecreateTask(activity, upIntent)) { TaskStackBuilder.Create(activity) .AddNextIntentWithParentStack(upIntent) .StartActivities(); } else { upIntent.AddFlags(ActivityFlags.ClearTop); activity.StartActivity(upIntent); } } activity.Finish(); }
public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case Android.Resource.Id.Home: // Some small additions to handle "up" navigation correctly var upIntent = NavUtils.GetParentActivityIntent(Activity); upIntent.AddFlags(ActivityFlags.ClearTask); // Check if up activity needs to be created (usually when // detail screen is opened from a notification or from the // Wearable app if (NavUtils.ShouldUpRecreateTask(Activity, upIntent) || Activity.IsTaskRoot) { // Synthesize parent stack Android.App.TaskStackBuilder.Create(Activity) .AddNextIntentWithParentStack(upIntent) .StartActivities(); } if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop) { // On Lollipop+ we finish so to run the nice animation Activity.FinishAfterTransition(); return(true); } // Otherwise let the system handle navigating "up" return(false); } return(base.OnOptionsItemSelected(item)); }
public override bool OnSupportNavigateUp() { Android.Content.Intent upIntent = NavUtils.GetParentActivityIntent(this); if (upIntent == null) { NavUtils.NavigateUpFromSameTask(this); return(true); } if (NavUtils.ShouldUpRecreateTask(this, upIntent)) { // this activity is not part of this app's task global::Android.Support.V4.App.TaskStackBuilder.Create(this).AddNextIntentWithParentStack(upIntent).StartActivities(); } else { // this activity is part of this app's task NavUtils.NavigateUpTo(this, upIntent); } return(true); }
public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case Android.Resource.Id.Home: var intent = NavUtils.GetParentActivityIntent(this); if (NavUtils.ShouldUpRecreateTask(this, intent)) { //This activity is not part of the app's tasks, so create new when navigating Android.Support.V4.App.TaskStackBuilder.Create(this). AddNextIntentWithParentStack(intent) .StartActivities(); } else { NavUtils.NavigateUpTo(this, intent); } break; } return(base.OnOptionsItemSelected(item)); }
public virtual bool SupportShouldUpRecreateTask(Intent targetIntent) { return(NavUtils.ShouldUpRecreateTask(this, targetIntent)); }