sharedpreferences - Android SharePrefrences issue -


i m having 3 activities 1 2 , 3 . activities have shared preferences . if user clicks when on activity 3 rd ,the data of replaces previous data of activity 1 . want when user clicks data of activity 3rd goes off , data in activity 1 remains is. can me plz ??

use following code store values in shared preferences:

sharedpreferences.editor editor = getsharedpreferences(my_prefs_name,                               mode_private).edit(); editor.putstring("name", "elena"); editor.putint("idname", 12); editor.commit(); 

if storing different values, should use different key-value pair when retrieving data. here retrieval code:

sharedpreferences prefs = getsharedpreferences(my_prefs_name, mode_private);  string restoredtext = prefs.getstring("text", null); if (restoredtext != null) { string name = prefs.getstring("name", "no name defined");//"no name defined" default value. int idname = prefs.getint("idname", 0); //0 default value. } 

in example above, replacing "name" , "elena" different key-value pair allow add different names sharedpreferences, can display on each unique activity accordingly.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -