0

I have a splash screen for my application that plays an mp3 clip on start up.

I want to give the user the option to disable/enable sound via a settings menu of my app. How can I implement this so that application remembers the user's preference every time they open the app.

Please see my code below for the sound.

public class Splash extends SherlockActivity {

SoundPool sp;
int explosion = 0;
MediaPlayer mp;

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    getSupportActionBar().hide();

    setContentView(R.layout.splash);

    sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
    explosion = sp.load(this, R.raw.soundfile, 1);

    Thread timer = new Thread() {
        public void run() {
            try {
                sleep(5000);

                if (explosion != 0)
                    sp.play(explosion, 1, 1, 0, 0, 1);

            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                Intent openMenu = new Intent(
                        "ttj.android.t3w.STARTINGPOINT");
                startActivity(openMenu);
            }

        }
    };
    timer.start();

}
tiptopjat
  • 499
  • 3
  • 13
  • 24

1 Answers1

2

Use SharedPreferences to store and retrieve it: http://developer.android.com/reference/android/content/SharedPreferences.html

Example: http://developer.android.com/guide/topics/data/data-storage.html#pref

public static final String PREFS_NAME = "MyPrefsFile";

//retrieve
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean silent = settings.getBoolean("silentMode", false);
//use silent

//store
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("silentMode", mSilentMode);
editor.commit();
RvdK
  • 19,580
  • 4
  • 64
  • 107