我正在尝试为我的 UNO 解决方案的 Android 部分实现启动画面。我可以让启动画面出现,等待几秒钟,但导航到主页后,我在 app.cs 中得到以下异常
protected override void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { // this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Windows.UI.Xaml.Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); <<<<< exception
未处理的异常:Java.Lang.NullPointerException:尝试在空对象引用上调用虚拟方法“android.content.res.Resources android.content.Context.getResources()”
堆栈跟踪很简单:
Uno1.App.OnLaunched 中的 0x25 在 C:\Users\pjsta\Documents\Visual Studio 2017\Projects\Uno1\Uno1\Uno1.Shared\App.xaml.cs:55,17 C#
解决方案的相关部分是1.我在Android项目中的新SplashActivity
[Activity(Label = "SplashScreen", MainLauncher = true, Theme = "@style/Theme.SplashActivity")]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
System.Threading.Thread.Sleep(1000);
StartActivity(typeof(MainActivity));
}
}
将 MainActivity 修改为不是 MainLauncher
[活动(MainLauncher = false,ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize,WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden)]
公共类 MainActivity : Windows.UI.Xaml.ApplicationActivity { }
相关样式加载到初始屏幕 OK。将 MainActivity 切换回 MainLauncher=true 可以工作,尽管没有启动屏幕。我是 Xamarin 和 Android 开发的新手,但精通 UWP。有没有人有任何想法?