Android : MvvmCross - Clear Task / New Task - Android

on Sunday, March 22, 2015


I'm developing an Android application using MvvmCross and I'm having some problems with ActivityFlags.NewTask and ActivityFlags.ClearTask.


I have 2 Activities one to login and another to show some data to the logged user. The problem is that when I start the new Activity sending the Flags NewTask and ClearTask it seems to work, pressing back closes the application (without passing through the login activity), but when i reopen it, it shows the login activity. If I kill the app and reopen it, it opens in the correct Activty (the second one). Anyone have any idea why this is happening?


My App.cs initialization:



if (SharedSettings.AppSettings.GetValue(SharedSettings.Keys.IsLoggedIn.ToString(), false))
{
RegisterAppStart<ViewModels.DataViewModel>();
}
else
{
RegisterAppStart<ViewModels.LoginViewModel>();
}


My ViewPresenter using a CustomHint:



public override void ChangePresentation (MvxPresentationHint hint)
{
if (hint is MvxRootPresentationHint)
{
var rootHint = hint as MvxRootPresentationHint;
var requestTranslator = Mvx.Resolve<IMvxAndroidViewModelRequestTranslator> ();
var newRootIntent = requestTranslator.GetIntentFor (new MvxViewModelRequest (rootHint.NewRootType, null, null, null));

newRootIntent.AddFlags(Android.Content.ActivityFlags.NewTask);
newRootIntent.AddFlags(Android.Content.ActivityFlags.ClearTask);
Activity.StartActivity (newRootIntent);
}
else
{
base.ChangePresentation (hint);
}
}


Resumed step by step sequence:



  • Open application - opens login activity

  • Do the login operation - opens the data activity

  • Press the back button - closes the application

  • Reopen the application - opens in login activity

  • Teminate the application - closes the application

  • Reopen the application - opens in data activity


0 comments:

Post a Comment