title: turn off sound for whole application android
body: <p>I am quite new to android and currently working on a quiz app in which I have sounds that play when users are using the app. I have a switch button in my settings activity in which should toggle sounds for the application on and off.
  I have implemented some logic but it ain't working yet. I have exhausted the much I know and I need some help.</p>
  
  <p><strong>style.xml</strong></p>
  
  <pre><code> &lt;!-- Base application theme. --&gt;
      &lt;style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"&gt;
          &lt;!-- Customize your theme here. --&gt;
          &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
          &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
          &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
          &lt;item name="android:soundEffectsEnabled"&gt;true&lt;/item&gt;
      &lt;/style&gt;
      &lt;style name="AppThemeMute" parent="Theme.AppCompat.Light.NoActionBar"&gt;
          &lt;!-- Customize your theme here. --&gt;
          &lt;item name="colorPrimary"&gt;@color/colorPrimary&lt;/item&gt;
          &lt;item name="colorPrimaryDark"&gt;@color/colorPrimaryDark&lt;/item&gt;
          &lt;item name="colorAccent"&gt;@color/colorAccent&lt;/item&gt;
          &lt;item name="android:soundEffectsEnabled"&gt;false&lt;/item&gt;
      &lt;/style&gt;
  </code></pre>
  
  <p><strong>MyApplication.java</strong></p>
  
  <pre><code>public class MyApplication extends Application {
  
      private static int sTheme;
  
      public final static int THEME_SOUND_ON = 0;
      public final static int THEME_SOUND_OFF = 1;
  
  
  
      @Override
      public void onCreate() {
          super.onCreate();
      }
  
      public static void changeToTheme(Context context, int theme) {
          sTheme = theme;
  
          switch (sTheme) {
              default:
              case THEME_SOUND_ON:
                  context.setTheme(R.style.AppTheme);
                  break;
              case THEME_SOUND_OFF:
                  context.setTheme(R.style.AppThemeMute);
                  break;
          }
      }
  }
  </code></pre>
  
  <p><strong>SettingsActivity.java</strong></p>
  
  <pre><code>public class SettingsActivity extends AppCompatActivity {
      private Switch mSoundSwitch;
      private  Switch mAdsSwitch;
      SharedPreferences sharedPreferences;
      SharedPreferences.Editor editor;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_settings);
          // handling switch button
          mSoundSwitch = (Switch) findViewById(R.id.soundSwitch);
          mSoundSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
  if (isChecked) {
      sharedPreferences =  getPreferences(Context.MODE_PRIVATE);
      editor = sharedPreferences.edit();
      editor.putBoolean("sound", true);
      editor.apply();
      // Change Whole App Theme
      MyApplication.changeToTheme(getApplicationContext(), MyApplication.THEME_SOUND_ON);
  } else {
      sharedPreferences =  getPreferences(Context.MODE_PRIVATE);
      editor = sharedPreferences.edit();
      editor.putBoolean("sound", false);
      editor.apply();
      MyApplication.changeToTheme(getApplicationContext(), MyApplication.THEME_SOUND_OFF);
  }
              }
          });
  
          sharedPreferences = getPreferences(Context.MODE_PRIVATE);
          boolean isChecked = sharedPreferences.getBoolean("sound", true);
          mSoundSwitch.setChecked(isChecked);
  
      }
  
  }
  </code></pre>
  
  <p>For now the switch button works perfectly with <code>sharedPreferences</code>. However, the sounds are not muted when the button is toggled.</p>