App resuming results in crash with FormsAppCompatActivity

后端 未结 2 1458
暗喜
暗喜 2021-01-18 10:01

I have a Xamarin Forms app, currently being built for Android. I have a MainActivity that used to extend FormsApplicationActivity, but because I wa

2条回答
  •  青春惊慌失措
    2021-01-18 10:33

    I solved it by adding a thread sleep in my OnResume method before setting the MainPage. My OnResume now looks like this:

    protected override void OnResume()
    {
        base.OnResume();
    
        Task.Delay(10).Wait();
    
        bool isRegistered = _authenticationService.IsRegistered();
    
        MainPage = isRegistered 
            ? new NavigationPage(new LoginPage()) 
            : new NavigationPage(new RegisterPage());
    }
    

    See this bug report for this workaround.

提交回复
热议问题