I'm fairly new with Java development and I started building a simple Android app. My MainActivity creates a SurfaceView called 'GameView' where I've created bouncing balls. An options menu is also created (in my MainActivity) which has a 'Settings' item. When tapping on the settings button, a new PreferenceActivity starts called SettingsActivity. In the settings menu I have to simple checkboxes that have to control the background music and sound effects (mute/unmute).
My checkboxes in the settings.xml:
<CheckBoxPreference
android:summary="Turn music on or off"
android:defaultValue="true"
android:title="Music"
android:key="musicPref"
/>
<CheckBoxPreference
android:summary="Turn sounds on or off"
android:defaultValue="true"
android:title="Sounds"
android:key="soundPref"
/>
I've used the following code in my public GameView function in order to get the value of the checkboxes:
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
musicPlaying = sharedPrefs.getBoolean("musicPref", true );
soundPlaying = sharedPrefs.getBoolean("soundPref", true );
EDIT: Do I have to define a click event in my settings menu in order to pass the changed value of my checkbox to my gameview?
How do I pass the changed value to my gameview?