判断是否是第一次启动——Android模块化编程
16lz
2021-01-26
//判断是否是第一次启动
// 如果没有,在onCreate方法中,SharedPreferences会新建一个数据aboutFirst,并新建一个boolean类型变量isFirst值设true。
// 如果有(非首次启动),isFirst已经设成false了,所以执行else
SharedPreferencessp=getSharedPreferences("aboutFirst",MODE_PRIVATE); booleanisFirst=sp.getBoolean("isFirst",true); if(isFirst==true){ SharedPreferences.Editoredit=sp.edit(); edit.putBoolean("isFirst",false); edit.commit();//这个很重要,部分网上资料没有写提交 Intentintent=newIntent(this,GuidesActivity.class); startActivity(intent); Toast.makeText(this,"第一次",Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(this,"+_+_+_不是第一次+_+_+",Toast.LENGTH_SHORT).show(); }
更多相关文章
- 应用程序启动速度优化
- android源码编译报错:prebuilts/misc/linux-x86/bison/bison: 没
- Android(安卓)Opencv例子Face-detection运行
- 消除 activity 启动时白屏、黑屏问题
- beagleboard 启动 android 内核
- Android(安卓)build system 分析之 envsetup.sh
- android中修改string.xml中变量
- android之在启动运用程序的时候彻底隐藏TitleBar
- 深入理解ActivityManagerService,你知道的不知道的全在这里!