How to save resource of ImageButton in shared preference?

ساخت وبلاگ

Vote count: 0

I have a series of ImageButtons in my app. Through the app, the user can set the background of the ImageButton to a drawable file.

This is working perfectly fine, when the user selects the image they would like and clicks a refresh button, the ImageButton's image changes.

The issue is, when I go to other activities the changed ImageButton's go and are returned to the default image.

I've been trying to do this through SharedPreferences. I've tried to get this working using all of the other similar questions on here with no luck.

What I know about storing images with SharedPreferences:I know that I have to convert the drawbable to a bitmap and then encode that into Base64 (because SharedPreferences will accept strings). I have done this, and I think the encoding is working.

I'm a complete beginner when it comes to SharedPreferences and I know that storing images isn't what it's built for, but it's the only way I can think of to solve my problem.

Any help would be MASSIVELY appreciated! Thanks in advance guys.

The way I'm encoding the drawbable to bitmap & base64:

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
grey11.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] grey11base64 = byteArrayOutputStream.toByteArray();
final String encodedGrey11 = Base64.encodeToString(grey11base64, Base64.DEFAULT);

In my main activity (where the images are displayed), I currently have OnCreate and onStop methods and an onClick for the refresh button.

asked 22 secs ago

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 231 تاريخ : چهارشنبه 6 ارديبهشت 1396 ساعت: 6:35