Skip to content Skip to sidebar Skip to footer

How To Use The Sharedpreferrence Value In Another Activity In Android App

in my app i am storing a value in Shared Preference and it gets stored successfully. Following is a piece of my code SharedPreferences prefs = getSharedPreferences( 'idValue', 0 );

Solution 1:

You can simply use

SharedPreferencesprefs=this.getSharedPreferences("idValue", MODE_WORLD_WRITEABLE);
Stringidvalue= prefs.getString("idValue", "");

in any activity you need

Solution 2:

first define Your public static SharedPreferences prefs = getSharedPreferences( "idValue", 0 ); as static in your main activity.

and other activity you can get value like this.

firstactivity_name.prefs.getString("idValue", null);

Post a Comment for "How To Use The Sharedpreferrence Value In Another Activity In Android App"