Skip to content Skip to sidebar Skip to footer

Shared Preference To Save Profile Image

In my app I want to make a profile page with default image profile and allow to user to change it by take a picture from camera or choose image from gallery, I did that successfull

Solution 1:

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

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

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.

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

Post a Comment for "Shared Preference To Save Profile Image"