我需要让活动仅在应用程序第一次运行时运行,这里我已经在第一次添加吐司,但我需要开始活动
Boolean isFirstRun = getSharedPreferences("PREFERENCE",MODE_PRIVATE).getBoolean("isfirstrun",true);
if(isFirstRun){
Toast.makeText(first_timerun.this,"first run",Toast.LENGTH_LONG).show();
getSharedPreferences("PREFERENCE",MODE_PRIVATE).edit().
putBoolean("isfirstrun",false).commit();
}
答案 0 :(得分:1)
在onCreate语句中发布以下代码
Boolean isFirstRun = getSharedPreferences(" PREFERENCE",MODE_PRIVATE) .getBoolean(" isFirstRun",true);
if (isFirstRun) {
//show start activity
startActivity(new Intent(MainActivity.this, Activity1.class));
Toast.makeText(MainActivity.this, "First Run", Toast.LENGTH_LONG)
.show();
}
getSharedPreferences("PREFERENCE", MODE_PRIVATE).edit()
.putBoolean("isFirstRun", false).commit();
将Activity1.class替换为您要启动的类