我有一个活动,只想在应用程序第一次运行时运行它。我检查了一个指定的共享首选项,它返回一个布尔值。如果返回true,则启动该活动并将其设置为false,这样下次打开应用程序时就不会运行它。但是我的实现出了问题。每次打开BeforMain1活动都会被打开。有人能建议我代码中的问题在哪里吗?
sharedPreferences = getSharedPreferences("ShaPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
boolean firstTime=sharedPreferences.getBoolean("first", true);
if(firstTime) {
editor.putBoolean("first",false);
Intent intent = new Intent(SplashScreen.this, BeforeMain1.class);
startActivity(intent);
}
else
{
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
startActivity(intent);
}