Skip to content Skip to sidebar Skip to footer

How To Set The Value Of Sharedpreferences In Other Activity?

I have two activities in my app. First activity SplashScreen and other SplashActivity. I have sharedPreferences in SplashScreen but i want to set value of this true in SplashActivi

Solution 1:

May be you are doing something wrong. you can do simply this in splash screen

if(pref.getBoolean("activity_executed", false))
   {
        Log.v("","Before if called");
        setContentView(R.layout.splash_screen);
        Log.v("","after if called");
        new Handler().postDelayed(csRunnable1, 5000);
        pref.edit().putBoolean("activity_executed", true).commit();
   } 

or in your splashactivity oncreate call this

getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE).edit().putBoolean("activity_executed", true).commit();

Solution 2:

Also call this in your SplashActivity

onCreate(...){
....
SharedPreferences pref;
SharedPreferences.Editor ed;
pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
ed = pref.edit();
ed.putBoolean("activity_executed", true);
ed.commit();
....
}

Post a Comment for "How To Set The Value Of Sharedpreferences In Other Activity?"