How to use SharedPreferences to save a URI, or any Storage?

前端 未结 3 1553
孤独总比滥情好
孤独总比滥情好 2021-01-02 14:19
URI imageUri = null;

//Setting the Uri of aURL to imageUri.
try {
    imageUri = aURL.toURI();
} catch (URISyntaxException e1) {
    // TODO Auto-generated catch bl         


        
3条回答
  •  醉梦人生
    2021-01-02 15:05

    To save the uri as a preference you first need to translate it to a string using the getPath() method. Then you can store it like this.

    SharedPreferences pref = getSharedPreferences("whateveryouwant", MODE_PRIVATE);
    SharedPreferences.Editor prefEditor = userSettings.edit();  
    prefEditor.putString("key", uriString);  
    prefEditor.commit();
    

提交回复
热议问题