You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin.Android使用Microsoft Intune时启动白屏问题求助

问题根因

Intune MAM SDK接管应用生命周期后,会对部分生命周期回调做线程调度,若UI初始化/导航操作没有明确指定在主线程执行,会被调度到后台线程,导致UI渲染阻塞,出现白屏无响应。

具体实现方案

1. 修正MainActivity中UI初始化逻辑,强制主线程执行

找到MainActivity1的OnMAMCreate方法,把Xamarin.Forms.Forms.Init、LoadApplication等UI相关操作包裹在主线程调度代码中,修改后的代码如下:

protected override void OnMAMCreate(Bundle bundle)
{
    Instance = this;
    base.OnMAMCreate(bundle);
    FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true);

    AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
    TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;

    // 强制UI相关操作在主线程执行
    RunOnUiThread(() => 
    {
        Xamarin.Forms.Forms.Init(this, bundle);
        DisplayCrashReport();
        LoadApplication(new App());
        FirebasePushNotificationManager.ProcessIntent(this, Intent);
    });
}

如果项目引入了Xamarin.Essentials,也可以替换为MainThread.BeginInvokeOnMainThread,效果一致。

2. 检查App启动后的初始导航逻辑

如果Xamarin.Forms App类构造完成后,存在跳转初始页面的导航逻辑,同样需要把这部分导航代码包裹在主线程调度中,示例如下:

// App.xaml.cs代码
public App()
{
    InitializeComponent();
    // 导航逻辑强制主线程执行
    MainThread.BeginInvokeOnMainThread(() => 
    {
        MainPage = new NavigationPage(new LoginPage()); // 替换为你的项目初始页面
    });
}

3. 可选排查点

如果修改后仍存在白屏问题,检查基类AppActivity的OnMAMCreate方法,将Rg.Plugins.Popup.Popup.Init也包裹到主线程执行即可。

内容的提问来源于stack exchange,提问作者Yanal Abo Hadhod

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 16:54:03