首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IntentFilter,开放表单视图

IntentFilter,开放表单视图
EN

Stack Overflow用户
提问于 2019-09-05 12:10:06
回答 2查看 362关注 0票数 0

我正在浏览器中进行用户身份验证。

成功通过身份验证后,浏览器将关闭,AndroidMainActivity.OnCreate()将被执行。但是,应用程序显示空白屏幕,就像没有加载视图/页面一样。我从MVVMCross (MvvmCross.Logging.MvxLog)获得这个日志,没有为LoadViewModel中的AndroidMainActivity指定ViewModel类。

所以现在看来,我应该导航到一些表格页,也许?但是导航对我没有任何帮助。也许我应该以不同的方式去做它,但是我找不到关于如何去做的任何文章或例子。

我现在就是这么做的:

代码语言:javascript
复制
    [Activity(MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    [IntentFilter([] { Intent.ActionView }, Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable }, DataScheme = GdspScheme.SCHEME)]
    public class AndroidMainActivity : MvxFormsAppCompatActivity<AndroidSetup, MainApplication, App>
    {
        protected override void OnCreate(Bundle bundle)
        {
            if (Intent.Data != null)
            {
                // user authenticated

                Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new NavigationPage(new FormsView()));
            }
        }
    }
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-09-17 15:49:15

我终于在MvvmCross文档中找到了解决方案:https://www.mvvmcross.com/documentation/advanced/customizing-appstart?scroll=100

代码语言:javascript
复制
public class App : MvxApplication
{
    public override void Initialize()
    {       
        RegisterCustomAppStart<AppStart>();
    }
}




    public class AppStart : MvxAppStart
{
    private readonly IAuthenticationService _authenticationService;

    public MvxAppStart(IMvxApplication application, IMvxNavigationService navigationService, IAuthenticationService authenticationService) : base(application, navigationService)
    {
        _authenticationService = authenticationService;
    }

    protected override void NavigateToFirstViewModel(object hint = null)
    {
        try
        {
            // You need to run Task sync otherwise code would continue before completing.
            var tcs = new TaskCompletionSource<bool>();
            Task.Run(async () => tcs.SetResult(await _authenticationService.IsAuthenticated()));
            var isAuthenticated = tcs.Task.Result;

            if (isAuthenticated)
            {
                //You need to Navigate sync so the screen is added to the root before continuing.
                NavigationService.Navigate<HomeViewModel>().GetAwaiter().GetResult();
            }
            else
            {
                NavigationService.Navigate<LoginViewModel>().GetAwaiter().GetResult();
            }
        }
        catch (System.Exception exception)
        {
            throw exception.MvxWrap("Problem navigating to ViewModel {0}", typeof(TViewModel).Name);
        }
    }
}
票数 0
EN

Stack Overflow用户

发布于 2019-09-05 13:00:51

当然,您应该在Forms项目中调用这一行。

您可以使用MessagingCenter

MainActivity

代码语言:javascript
复制
if (Intent.Data != null)
{
  // user authenticated
  MessagingCenter.Send<Object>(this, "authenticatedFinished");
  
}

在窗体->the构造函数中的MainPage

代码语言:javascript
复制
public xxxMainPage()
{
  //...
  MessagingCenter.Subscribe<Object>(this, "authenticatedFinished", () =>
  {   
      Navigation.PushAsync(new NavigationPage(new FormsView()));
                        
  });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57805178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档