且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

共享首选项以保存个人资料图片

更新时间:2023-02-02 21:01:37

在onActivityResult()"方法中,将获取到的imageUri(或imagePath)保存到sharedPreferences.

In the "onActivityResult()" method, save the imageUri (or imagePath) obtained to sharedPreferences.

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
SharedPreferences.Editor edit = preferences.edit();
edit.putString(key, value);
edit.apply();

检查 sharedPreference 值是否不是空字符串,而不是使用布尔值.如果 sharedPreference 值不是空字符串,则使用来自 sharedPreference 的 imageUri(或 imagePath)更新图像视图.

Instead of using boolean, check if sharedPreference value is not a null string.If the sharedPreference value is not a null string, update the imageview with imageUri (or imagePath) from sharedPreference.

要在 imageView 中加载图像,我建议您使用照片加载库,例如 Picasso滑翔.

For loading image in imageView, i recommend you to use photo loading libraries like Picasso or Glide.