I have an activity that I only want to run when the application launches for the first time. I checked the highlighted shared preference, which returns a boolean. If it returns true, it will be launched, and it will be set to false, so that it will not start the next time the application is opened. But my implementation went wrong. Every time I open, BeforMain1 activity becomes open. Can someone tell me what is wrong in my code?
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);
}
source
share