Skip to content

Instantly share code, notes, and snippets.

@ChrisRisner
Created August 12, 2012 01:55
Show Gist options
  • Save ChrisRisner/3328829 to your computer and use it in GitHub Desktop.
Save ChrisRisner/3328829 to your computer and use it in GitHub Desktop.
Sharing Shared Preferences between Android Apps
Context myContext = getApplicationContext().createPackageContext
("com.cr.sharedprefexampleone", Context.MODE_WORLD_WRITEABLE);
SharedPreferences testPrefs = myContext.getSharedPreferences
("sharedprefone", Context.MODE_WORLD_READABLE);
String prefString = testPrefs.getString("time", "Couldn't find");
SharedPreferences prefs = getApplicationContext().
getSharedPreferences("sharedprefone", Context.MODE_WORLD_READABLE);
Editor edit = prefs.edit();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date(); //
edit.putString("time", dateFormat.format(date));
edit.commit();
Copy link

ghost commented Oct 29, 2015

After accessing data 1st time in 2nd app, then change the data in 1st app and then again access data in 2nd app is old not latest data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment