I have a problem with Xamarin Forms and Mvvm Cross on Android. In my app, I need to navigate between Master Detail page and my other pages that are not a part of my master detail page. At some point (after I minimize and resume an app) when I navigate somewhere I get blank page with no UI instead of an expected page. No exceptions are thrown. Below you can find a link to a simple project that you can reproduce the issue:
https://github.com/grinh/blankpage
Here are steps to reproduce it:
Below you can find simplified classes that can be used to reproduce issue. (I use MvvmCross ver. 5.6.3 and Xamarin Forms ver. 2.5.0.121934):
LoginPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<views:MvxContentPage x:TypeArguments="vm:LoginViewModel" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
xmlns:vm="clr-namespace:BlankScreenApp.ViewModels;assembly=BlankScreenApp"
x:Class="BlankScreenApp.Views.LoginPage">
<views:MvxContentPage.Content>
<StackLayout>
<Button Text="Quick guide" x:Name="QuickGuideButton" Clicked="QuickGuideButtonClicked" />
</StackLayout>
</views:MvxContentPage.Content>
</views:MvxContentPage>
LoginPage.xaml.cs
[MvxContentPagePresentation(NoHistory = true)]
public partial class LoginPage
{
public LoginPage()
{
InitializeComponent();
}
private async void QuickGuideButtonClicked(object sender, EventArgs eventArgs)
{
await Mvx.Resolve<IMvxNavigationService>().Navigate<QuickGuideViewModel>();
}
}
QuickGuide.xaml
<?xml version="1.0" encoding="utf-8" ?>
<views:MvxContentPage x:TypeArguments="viewModels:QuickGuideViewModel" xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:views="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
xmlns:viewModels="clr-namespace:BlankScreenApp.ViewModels;assembly=BlankScreenApp"
x:Class="BlankScreenApp.Views.QuickGuidePage">
<views:MvxContentPage.Content>
<StackLayout Padding="40">
<Label Text="Some text comes here." />
</StackLayout>
</views:MvxContentPage.Content>
</views:MvxContentPage>
QuickGuide.xaml.cs
[MvxContentPagePresentation(NoHistory = true)]
public partial class QuickGuidePage
{
public QuickGuidePage()
{
InitializeComponent();
}
}
CoreApp.cs
public class CoreApp : MvxApplication
{
public override void Initialize()
{
RegisterNavigationServiceAppStart<LoginViewModel>();
}
}
Setup.cs
public class Setup : MvxFormsAndroidSetup
{
public Setup(Context applicationContext) : base(applicationContext)
{
}
protected override MvxFormsApplication CreateFormsApplication()
{
return new BlankScreenApp.App();
}
protected override IMvxApplication CreateApp()
{
return new BlankScreenApp.CoreApp();
}
protected override IMvxTrace CreateDebugTrace()
{
return new DebugTrace();
}
}
MainActivity.cs
[Activity(Label = "BlankScreenApp", Icon = "@drawable/icon", Theme = "@style/MainTheme", ScreenOrientation = ScreenOrientation.Portrait, LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : MvxFormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
}
}