I have a splash activity in my app and intro .. What i wanna do is showing intro activity only in the first run so i used share preference to do so
Here is my codes
Splash Activity
Handler handler = new Handler();
handler.postDelayed(() -> {
if (sharedPref != null && !sharedPref.loadIntroDone()) {
Intent intent = new Intent(SplashActivity.this, IntroSliders.class);
startActivity(intent);
finish();
} else {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}, 4000);
Shared Preference
public Boolean loadIntroDone() {
return (mySharedPref == null) || mySharedPref.getBoolean("IntroDone", false);
}
It causes crash after splash activity appear
Error
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Boolean com.example.example.SharedPref.loadIntroDone()' on a null object reference