Android应用程序在安装后第二次运行时仅显示白屏

时间:2018-10-30 12:58:40

标签: android xamarin.forms

这个问题我不知所措。

当我使用发行版配置部署应用程序或通过侧面加载安装应用程序时,第一次运行(安装后即刻)运行正常。

如果我尝试在关闭应用程序后再次运行该应用程序(通过在菜单中找到该应用程序),则该应用程序会打开但会停留在白屏上。

这是任何人之前遇到的问题吗?第一次打开应用程序与第二次打开应用程序之间有功能上的区别吗?

编辑:启动时运行的代码

主要活动

protected override void OnCreate(Bundle bundle)
    {            
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        ImageCircle.Forms.Plugin.Droid.ImageCircleRenderer.Init();
        Syncfusion.XForms.Android.PopupLayout.SfPopupLayoutRenderer.Init();
        CrossCurrentActivity.Current.Init(this, bundle);

        var  dbPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "ForSiteSQLite.db3");

        if (Intent.Extras != null)
        {
            foreach (var key in Intent.Extras.KeySet())
            {
                var value = Intent.Extras.GetString(key);//This is where we can make the notifications do special things

                if (key == "Type")
                {
                    if (Intent.Extras.GetString(key) == "Case Assignment")
                    {
                        LoadApplication(new App(dbPath, "Case Assignment"));
                    }
                }
            }
        }
        else
        {
            LoadApplication(new App(dbPath));
        }

        int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this);
        if (resultCode != ConnectionResult.Success)
        {
            if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode))
            {
                Notification.Builder builder = new Notification.Builder(CurrentContext.ApplicationContext, "default")
                .SetContentTitle("Error")
                .SetContentText(GoogleApiAvailability.Instance.GetErrorString(resultCode));


                // Build the notification:
                Notification notification = builder.Build();

                // Get the notification manager:
                NotificationManager notificationManager =
                    GetSystemService(Context.NotificationService) as NotificationManager;

                // Publish the notification:
                const int notificationId = 0;
                notificationManager.Notify(notificationId, notification);
            }
            else
            {
                Notification.Builder builder = new Notification.Builder(CurrentContext.ApplicationContext, "default")
                .SetContentTitle("Error")
                .SetContentText("This device is not supported");


                // Build the notification:
                Notification notification = builder.Build();

                // Get the notification manager:
                NotificationManager notificationManager =
                    GetSystemService(Context.NotificationService) as NotificationManager;

                // Publish the notification:
                const int notificationId = 0;
                notificationManager.Notify(notificationId, notification);
                Finish();
            }
        }

        CreateNotificationChannel();
    }

    void CreateNotificationChannel()
    {
        if (Build.VERSION.SdkInt < BuildVersionCodes.O)
        {
            // Notification channels are new in API 26 (and not a part of the
            // support library). There is no need to create a notification
            // channel on older versions of Android.
            return;
        }

        var channel = new NotificationChannel(CHANNEL_ID,
                                              "FCM Notifications",
                                              NotificationImportance.Default)
        {

            Description = "Firebase Cloud Messages appear in this channel"
        };

        var notificationManager = (NotificationManager)GetSystemService(Android.Content.Context.NotificationService);
        notificationManager.CreateNotificationChannel(channel);
    }

App.xaml.cs

public App(string dbPath)
    {
        RegisterSyncfusion();
        InitializeComponent();
        database = new LocalDB(dbPath);
        MainPage = new LoginPage();
    }

private void RegisterSyncfusion()
    {
        //Register Syncfusion license
        Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("REDACTED");
    }

LoginPage.xaml.cs

public LoginPage()
    {
        InitializeComponent ();

        vm = new LoginViewModel();

        if (Helpers.Settings.Username != "" && Helpers.Settings.Password != "")
        {
            chkRemember.IsChecked = true;

            txtUsername.Text = Helpers.Settings.Username;
            txtPassword.Text = Helpers.Settings.Password;

            AttemptLogin();
        }
    }

0 个答案:

没有答案