- URI imageUri = null;
- //Setting the Uri of aURL to imageUri.
- try {
- imageUri = aURL.toURI();
- } catch (URISyntaxException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
我正在使用此代码将URL转换为URI.我怎样才能将imageUri保存到SharedPreferences,或者将其删除的内存不能删除onDestroy()?
解决方法
要开始使用SharedPreferences进行存储,您需要在onCreate()中使用类似的内容:
- SharedPreferences myPrefs = getSharedPreferences(myTag,0);
- SharedPreferences.Editor myPrefsEdit = myPrefs.edit();
我认为你可以做这样的事情来存储它:
- myPrefsEdit.putString("url",imageUri.toString());
- myPrefsEdit.commit();
然后这样的东西来检索:
- try {
- imageUri = URI.create(myPrefs.getString("url","defaultString"));
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }