Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin 当我杀死正在运行的实例并使用Db ecncryption重新启动应用程序时,应用程序正在崩溃_Xamarin - Fatal编程技术网

Xamarin 当我杀死正在运行的实例并使用Db ecncryption重新启动应用程序时,应用程序正在崩溃

Xamarin 当我杀死正在运行的实例并使用Db ecncryption重新启动应用程序时,应用程序正在崩溃,xamarin,Xamarin,我已经实现了以下场景的代码 namespace Inspect.Droid { public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity { private DataBaseEncryption dbEncryption; protected override async void OnCreate(B

我已经实现了以下场景的代码

namespace Inspect.Droid
{

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{             
    private DataBaseEncryption dbEncryption;             
    protected override async void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        MainAppActivity = this;
        Forms.Init(this, bundle);
        //to get the current device language code
        var code = Locale.Default.GetDisplayLanguage(Locale.Default);
        CommonInfo.Instance.DeviceCurrentLanguageCode = code.Substring(0, 2).ToUpper();
        Console.WriteLine("Device lang code: " + CommonInfo.Instance.DeviceCurrentLanguageCode);
        try
        {
            ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current);
        }
        catch (Exception ex)
        {
            //when application coming back from background throws exception, bcz PCLAppConfig is already initialized, so as there is no change no need to change here
            Console.WriteLine(ex.Message);
        }
        GLOBAL_CONTEXT = Android.App.Application.Context;
        ACTIVITY_CONTEXT = this;
        FragmentMgr = FragmentManager;
        dbEncryption = new DataBaseEncryption();
        //await PrepareDb();
        await  dbEncryption.InitiateDecryption();
        //AzureMobileServices Initialization for Android
        Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
        SessionInfo.Instance.DeviceId = Utility.GenerateGuid().ToString();

        //This will set the value for _skipCount variable in all respected helper classes.
        SetSkipCount();
        Inspect.ScreenSize = new Xamarin.Forms.Size(Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density,
        Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density);

        Inspect.AndroidDisplayMetricsDensity = Resources.DisplayMetrics.Density;
        int statusBarResId = Resources.GetIdentifier("status_bar_height", "dimen", "android");
        if (statusBarResId > 0)
        {
            Inspect.AndroidStatusBarHeight = Resources.GetDimensionPixelSize(statusBarResId);
        }

        Context context = this.ApplicationContext;
        Acr.UserDialogs.UserDialogs.Init(this);

        //allowing the device to change the screen orientation based on the rotation
        MessagingCenter.Subscribe<InspectionAddNotesPage>(this, CommonConstants.AllowLandScape, sender =>
        {
            RequestedOrientation = ScreenOrientation.Unspecified;
        });
        //during page close setting back to portrait
        MessagingCenter.Subscribe<InspectionAddNotesPage>(this, CommonConstants.PreventLandScape, sender =>
        {
            RequestedOrientation = ScreenOrientation.Portrait;
        });
        LoadApplication(new Inspect());
        //Intializing the context for Media access
        CrossCurrentActivity.Current.Activity = this;
        PasscodeAuthDependency.Activity = this;
    }



    protected override void OnStop()
    {
        base.OnStop();

        dbEncryption.InitiateEncryption(true);

    }
    protected override void OnRestart()
    {
        base.OnRestart();
        dbEncryption.InitiateDecryption();


    }
    protected override void OnDestroy()
    {
        base.OnDestroy();

    }
namespace Inspect.Droid
{
公共类主活动:全局::Xamarin.Forms.Platform.Android.Forms应用活动
{             
私有数据库加密;
受保护的重写异步void OnCreate(捆绑包)
{
base.OnCreate(bundle);
MainAppActivity=this;
Forms.Init(这个,bundle);
//获取当前设备语言代码的步骤
var code=Locale.Default.GetDisplayLanguage(Locale.Default);
CommonInfo.Instance.DeviceCurrentLanguageCode=code.Substring(0,2).ToUpper();
Console.WriteLine(“设备语言代码:+CommonInfo.Instance.DeviceCurrentLanguageCode”);
尝试
{
初始化(PCLAppConfig.FileSystemStream.PortableStream.Current);
}
捕获(例外情况除外)
{
//当应用程序从后台返回时抛出异常,bcz PCLAppConfig已经初始化,所以这里不需要更改
控制台写入线(例如消息);
}
全局上下文=Android.App.Application.CONTEXT;
活动上下文=此;
FragmentMgr=FragmentManager;
dbEncryption=新数据库加密();
//等待准备b();
wait dbEncryption.initialedecryption();
//Android的AzureMobileServices初始化
Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
SessionInfo.Instance.DeviceId=Utility.GenerateGuid().ToString();
//这将在所有受尊重的助手类中设置_skipCount变量的值。
SetSkipCount();
Inspect.ScreenSize=new Xamarin.Forms.Size(Resources.DisplayMetrics.WidthPixels/Resources.DisplayMetrics.Density,
Resources.DisplayMetrics.HeightPixels/Resources.DisplayMetrics.Density);
Inspect.AndroidDisplayMetricsDensity=Resources.DisplayMetrics.Density;
int statusBarResId=Resources.GetIdentifier(“status\u bar\u height”、“dimen”、“android”);
如果(SID>0)
{
Inspect.AndroidStatusBarHeight=Resources.GetDimensionPixelSize(statusBarResId);
}
Context=this.ApplicationContext;
Acr.UserDialogs.UserDialogs.Init(此);
//允许设备根据旋转改变屏幕方向
订阅(此,CommonConstants.AllowLandScape,发件人=>
{
RequestedOrientation=屏幕方向。未指定;
});
//在页面关闭过程中,设置回纵向
MessagingCenter.Subscribe(此,CommonConstants.PreventLanguage,发件人=>
{
RequestedOrientation=屏幕方向。纵向;
});
加载应用程序(新的Inspect());
//初始化媒体访问的上下文
CrossCurrentActivity.Current.Activity=此;
PasscodeAuthDependency.Activity=this;
}
受保护的覆盖void OnStop()
{
base.OnStop();
dbEncryption.InitiateEncryption(true);
}
受保护的重写void OnRestart()
{
base.OnRestart();
dbEncryption.initialedecryption();
}
受保护的覆盖无效OnDestroy()
{
base.ondestory();
}

请提供解决方案。

您的异常具体来自何处?您是否设法获取了来源? 如果您正在讨论ConfigurationManager.Initialize()方法中的异常,请尝试以下操作

if(Configurationmanager.AppSettings == null)
{
    ConfigurationManager.Initialise(PCLAppConfig.FileSystemStream.PortableStream.Current);
}
只是ConfigurationManager在发现已初始化的NameValueCollection时抛出异常