Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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.android 如何知道在xamarin android中安装后是否首次打开应用程序_Xamarin.android - Fatal编程技术网

Xamarin.android 如何知道在xamarin android中安装后是否首次打开应用程序

Xamarin.android 如何知道在xamarin android中安装后是否首次打开应用程序,xamarin.android,Xamarin.android,正如问题所说,我如何知道该应用程序是首次在android用户设备上启动的?使用SharedReferences了解应用程序是第一次还是第二次打开。此代码应该在您的应用程序启动时出现,就像您的main活动的OnCreate var pref = PreferenceManager.GetDefaultSharedPreferences(Application.Context); var editorLogin = pref.Edit(); if (pref.GetBoolean("firstTi

正如问题所说,我如何知道该应用程序是首次在android用户设备上启动的?

使用
SharedReferences
了解应用程序是第一次还是第二次打开。此代码应该在您的应用程序启动时出现,就像您的
main活动的
OnCreate

var pref = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
var editorLogin = pref.Edit();

if (pref.GetBoolean("firstTime", true))
{
    Toast.MakeText(this, "App opening first time", ToastLength.Short).Show();
    editorLogin.PutBoolean("firstTime", false).Commit();
}
else
{
    Toast.MakeText(this, "App opening second time", ToastLength.Short).Show();
}

我知道有两种方法可以实现这一点——简单的方法是共享首选项,因为它们可以从android端获得,而且非常轻量级

相当于
SharedReferences
的Xamarin.Android是一个名为
IsSharedReferences
的接口

例如,要使用某些
上下文保存真/假
bool
,可以执行以下操作:

ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (mContext);
ISharedPreferencesEditor editor = prefs.Edit ();
editor.PutBoolean ("is_first_time", mBool);
// editor.Commit();    // applies changes synchronously on older APIs
editor.Apply();        // applies changes asynchronously on newer APIs
使用以下命令访问保存的值:

ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences (mContext);
mBool = prefs.GetBoolean ("is_first_time", <default value>);  
if(mBool)
{
 //this is first time   
 prefs.PutBoolean ("is_first_time", false).Apply();
}
else
{
//this is second time onwards
// your piece of code
}
IsSharedReferences prefs=PreferenceManager.GetDefaultSharedReferences(mContext);
mBool=prefs.GetBoolean(“是第一次”);
如果(mBool)
{
//这是第一次
prefs.PutBoolean(“is_first_time”,false).Apply();
}
其他的
{
//这是第二次了
//你的代码
}

感谢您的重播,我将尝试此重播。感谢您的回复,我将尝试此重播。