-1

How do I save the back ground setting in the app and when it exits back it still saves that background As the default app I to be :

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg2"
android:id="@+id/bgplayer">

and click button

 bgplayer.setBackgroundResource(R.drawable.bg1a);

If you want to completely exit the app and re-enter the background it will be bga1

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1

Use shared preferences in Activity:

SharedPreferences prefs = getSharedPreferences(
  "com.example.app", Context.MODE_PRIVATE);

then save like this:

prefs.edit().putInt("your_key", R.drawable.bg1a).apply();

and read like this:

int value = prefs.getInt("your_key", defaultIntValue);

And set background as:

bgplayer.setBackgroundResource(value);
mac229
  • 4,319
  • 5
  • 18
  • 24