0

I have defined array of ImageButton dynamically and that will take its buttons background from the user selected photos, my problem is that when I restart the app, the image buttons does not stay, how can I make it stay "along with the user selected background for it" without define it in the XML? I think of shared preferences but I am not sure if it will solve the problem!

icon[count]= new ImageButton(this);
icon[count].setImageResource(R.drawable.p1);
icon[count].setImageBitmap(photo);
camelCaseCoder
  • 1,379
  • 15
  • 31
A.Huseein
  • 11
  • 4

1 Answers1

0

To save Background color you have applied , Shared preferences is perfect solution.

You need to save state of background color and retrieve it when you are restarting app(onRestart()) or onPause() or onResume().

how can I make it stay "along with the user selected background for it" without define it in the XML?

Using Shared preferences

Checkout Android Shared preferences example

Community
  • 1
  • 1
Amit Vaghela
  • 21,317
  • 19
  • 79
  • 131
  • it is image background not just color .shared preferences solve the problem too?if yes can you help me how to make that? – A.Huseein Feb 09 '16 at 07:03
  • yes, you can. check another example http://androidopentutorials.com/android-how-to-store-list-of-values-in-sharedpreferences/ – Amit Vaghela Feb 09 '16 at 07:14