public class MainActivity extends Activity{
SharedPreferences share;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//判断是否第一次登录,第一次登录要跳到欢迎页
frist();
}
public void frist(){
share = getSharedPreferences("count", MODE_WORLD_READABLE);
//读取SharedPreferences里conunt数据
int count = share.getInt("count", 0);
//显示程序以前使用次数
Toast.makeText(this, "程序以前被使用了"+count+"次", Toast.LENGTH_LONG).show();
//如果是第一次使用则跳转到欢迎页
if (count == 0) {
Intent intent = new Intent();
intent.setClass(MainActivity.this, Welcome.class);
startActivity(intent);
finish();
}
//存入数据
Editor editor = share.edit();
editor.putInt("count", ++count);
//提交修改
editor.commit();
}
}
使用SharedPreferences记录应用使用次数,判断是否加载导航页
最新推荐文章于 2021-10-21 13:00:14 发布