How to store and retrieve bitmap in sharedPreferences in Android?

前端 未结 4 1510
遥遥无期
遥遥无期 2020-12-03 18:14

I am new in Android. I want to store my bitmap in sharedPreferences. Can anyone tell me how it will possible? Actually my requirements is, I fetch the image from gallery as

4条回答
  •  猫巷女王i
    2020-12-03 18:24

    You can add values in SharedPreference like this:

    SharedPreferences pref = getSharedPreferences("abc", 0);
    Editor edit = pref.edit();
    edit.putBoolean(arg0, arg1);
    edit.putFloat(arg0, arg1);
    edit.putInt(arg0, arg1);
    edit.putLong(arg0, arg1);
    edit.putString(arg0, arg1);
    edit.commit();
    

    You can add only Boolean, Float, Int, Long, String values in SharedPreference.

    To store image you should external or internal memory of device.

提交回复
热议问题