-
-
Save bhardwajAbhi/4d957a24d4d9baa60700b2769eebbf31 to your computer and use it in GitHub Desktop.
Sharing Shared Preferences between Android Apps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment