开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜