RSS

Android Accessing Preferences in an Actitvity

04 Jul

I though I could somehow give the user an option of muting the sound in the splash screen(Click here to check out the sourcecode). So in here i set up the preferences, Now we want to read those preferences and use them accordingly. I modified the splash screen such that it will only play music if the user has set it to.
So first you have to access the Preferences:

SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

Now well check the value of the checkbox and store it in boolean variable playMusic

boolean playMusic = getPrefs.getBoolean("sound", true);

Now to the block of code should look like:

SharedPreferences getPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
		boolean playMusic = getPrefs.getBoolean("sound", true);
		
		if(playMusic)
			song.start();
Advertisements
 
1 Comment

Posted by on July 4, 2012 in Android, Android tutorials, Code

 

Tags:

One response to “Android Accessing Preferences in an Actitvity

  1. Mauricio Ponce (@th4n0)

    April 22, 2013 at 3:07 pm

    thanks, it was very useful

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: