java - Xamarin、Android Activity 、IntentFilter、打开表单 View

标签 java android xamarin.forms mvvmcross

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

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

所以看起来现在我应该导航到某些表单页面??? 然而导航对我没有任何作用。也许我应该采取不同的做法,但我找不到任何关于如何做到这一点的文章或示例。

这就是我现在正在尝试的方法:

    [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()));
            }
        }
    }

最佳答案

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

您可以使用消息中心

MainActivity

if (Intent.Data != null)
{
  // user authenticated
  MessagingCenter.Send<Object>(this, "authenticatedFinished");
  
}

在 Forms 中 ->MainPage 的构造函数

public xxxMainPage()
{
  //...
  MessagingCenter.Subscribe<Object>(this, "authenticatedFinished", () =>
  {   
      Navigation.PushAsync(new NavigationPage(new FormsView()));
                        
  });
}

关于java - Xamarin、Android Activity 、IntentFilter、打开表单 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57805178/

相关文章:

java - 模拟 ScheduledExecutorService.scheduleWithFixedDelay(...) 返回 null

java - Ivy :publish work?怎么办

android - WallpaperServices 绘制方法的类无效方法

android - Android window.device 上的 PhoneGap 未定义

ios - 如何修复上传 ipa 到 AppStore 时出现“"' CFBundleIconName' is Missing”错误?

java - oracle.sql.BLOB.DURATION_CALL 与 oracle.sql.BLOB.DURATION_SESSION 之间的区别

java - 什么是 ForkJoinPool 异步模式

android - 轻型导航栏

android - Xamarin.Forms 中类似 colorAccent 的属性

listview - 在 ListView Xamarin 表单中滚动时图像消失