How to read and write URI type using sharedPreferences
Actually I want to know, how can I read and write URI using sharedPreferences
. I mean to say that suppose I have an int value, e.g.:
int x = 10;
Then for write date using sharedPrferences
I used following code
SharedPreferences preferencesWrite = getSharedPreferences("myPreferences", 0);
SharedPreferences.Editor editor = preferencesWrite.edit();
editor.putInt("value", x);
editor.commit();
And similarly for reading data code I used is
x = preferencesRead.getInt("value", 0);
Now if I declared Uri calenEvent;
Then how ca开发者_如何学编程n I read and write it to the register? If anyone knows, please help me to solve this out.
Covert URI to string
String uriStr = uri.toString();
You can save this string in SharedPreference easily.
and later reconstruct URI from the string
URI uri = new URI(uriString);
精彩评论