And*_*Boy -2 android android-activity
我的问题告诉了一切.有没有关于第一次安装活动的想法.
实际上我想检查活动是否是第一次安装b'coz我正在使用一个变量检查是否应该第一次安装
真正
否则它改变了
假
您可以将数据存储在"首选项"中,如下面的代码.
SharedPreferences settings = getSharedPreferences("MyPrefs", 0);
if (settings.getBoolean("is_first_time", true)) {
//the app is being launched for first time, do something
Log.d("TAG", "First time");
// first time task
// record the fact that the app has been started at least once
settings.edit().putBoolean("is_first_time", false).commit();
}
else
{
//second time launch..
}
Run Code Online (Sandbox Code Playgroud)
当您第一次启动应用程序时,如果 condition将返回true,因为第一次没有存储数据且默认值为True.所以第二次由于is_first_time值为False而无法执行.
注意
上面的代码将驻留在onCreate方法中.
| 归档时间: |
|
| 查看次数: |
1195 次 |
| 最近记录: |