使用SharedPreferences记录应用使用次数,判断是否加载导航页

来源:互联网 发布:粑粑是什么网络意思 编辑:程序博客网 时间:2024/04/20 11:21
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();}}

0 0