Created
October 30, 2015 10:45
-
-
Save munkii/2304f9a90eea81257e08 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace OurProj.Framework.Droid.Views | |
{ | |
using System; | |
using System.Collections.Generic; | |
using Android.Content; | |
using Cirrious.MvvmCross.Droid.Views; | |
using Cirrious.MvvmCross.ViewModels; | |
/// <summary> | |
/// Custom AndroidViewsContainer used solely to stop the NewTask activity flag from being added to the LoginView Intent fired after Unlock | |
/// </summary> | |
public class CustomDroidViewsContainer : MvxAndroidViewsContainer | |
{ | |
/// <summary> | |
/// A list of the activities shown with ActivityFlags.NewTask and ActivityFlags.ClearTask | |
/// </summary> | |
private List<string> activitiesShownWithNewAndClear = new List<string>(); | |
/// <summary> | |
/// Initializes a new instance of the <see cref="CustomDroidViewsContainer"/> class. | |
/// </summary> | |
/// <param name="applicationContext">The application context.</param> | |
public CustomDroidViewsContainer(Context applicationContext) : base(applicationContext) | |
{ | |
} | |
/// <summary> | |
/// Loads the specified intent. | |
/// </summary> | |
/// <param name="intent">The intent.</param> | |
/// <param name="savedState">State of the saved.</param> | |
/// <returns>Some cool stuff</returns> | |
public override IMvxViewModel Load(Intent intent, IMvxBundle savedState) | |
{ | |
this.LogIfClearTaskNewTask(intent); | |
return base.Load(intent, savedState); | |
} | |
/// <summary> | |
/// Loads the specified intent. | |
/// </summary> | |
/// <param name="intent">The intent.</param> | |
/// <param name="savedState">State of the saved.</param> | |
/// <param name="viewModelTypeHint">The view model type hint.</param> | |
/// <returns>Some cool stuff</returns> | |
public override IMvxViewModel Load(Intent intent, IMvxBundle savedState, Type viewModelTypeHint) | |
{ | |
this.LogIfClearTaskNewTask(intent); | |
return base.Load(intent, savedState, viewModelTypeHint); | |
} | |
/// <summary> | |
/// Adjusts the intent for presentation. | |
/// </summary> | |
/// <param name="intent">The intent.</param> | |
/// <param name="request">The request.</param> | |
protected override void AdjustIntentForPresentation(Intent intent, MvxViewModelRequest request) | |
{ | |
// The default MvxAndroidViewsContainer code add ActivityFlags.NewTask to all Intents. | |
// This is a problem when an Activity has subsequently been shown using the combination of NewTask and ClearTask | |
if (this.activitiesShownWithNewAndClear.Contains(intent.Component.ClassName)) | |
{ | |
// I wanted to remove the NewTask flag that base.AdjustIntentForPresentation | |
// added as a default but Flags is a readonly property so just going to have to skip | |
// base.AdjustIntentForPresentation(intent, request); | |
////ActivityFlags flags = intent.Flags; | |
////flags &= ~ActivityFlags.NewTask; | |
////intent.AddFlags(flags); | |
} | |
else | |
{ | |
base.AdjustIntentForPresentation(intent, request); | |
} | |
} | |
/// <summary> | |
/// Logs the Intent's Component class name if the Intent is being shown as a ClearTask and NewTask | |
/// </summary> | |
/// <param name="intent">The intent.</param> | |
private void LogIfClearTaskNewTask(Intent intent) | |
{ | |
if (intent.Flags.HasFlag(ActivityFlags.NewTask) && intent.Flags.HasFlag(ActivityFlags.ClearTask)) | |
{ | |
if (!this.activitiesShownWithNewAndClear.Contains(intent.Component.ClassName)) | |
{ | |
this.activitiesShownWithNewAndClear.Add(intent.Component.ClassName); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is my custom Presenter that works around the NewTask being added