Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to turn sound on/off globally in Android game
    primarykey
    data
    text
    <p>I am working on Android game and I am providing options menu to "Turn On" or "Turn Off" the sounds and vibration of the game .I have 3 Activity and i want that if i OFF the Sound or Vibrate from any Activity of My Game it has to be OFF in all other Activity even if i move to one activity to another activity and if from any one activity i again turn ON the sound or vibration of the game it has to ON in all the other activity of the game .The basic problem is that I am not able to do that and i am confused in this. i am also not sure that which method i use to do that.Please Help me . i have 3 class: 1)Helper Class(MySetting) 2)class1(main class) 3)class 2</p> <p>Class 1(main code i try is)</p> <pre><code>if(MySetting.mp.isPlaying()==true){ ms.setSoundON(true); } else { ms.loadAudio(this); MySetting.PlaySound(); ms.setSoundOFF(false); ms.setSoundON(true); } Button ON=(Button)findViewById(R.id.Start); ON.setOnClickListener(new OnClickListener() { public void onClick(View v) { if(ms.isSoundON()==false){ ms.loadAudio(Class1.this); MySetting.PlaySound(); ms.setSoundOFF(false); ms.setSoundON(true); tv.setText("Sound is Start"); } else { ms.setSoundON(true); } } }); Button OFF=(Button)findViewById(R.id.stop); OFF.setOnClickListener(new OnClickListener() { public void onClick(View v) { MySetting.StopSound(); ms.setSoundOFF(true); ms.setSoundON(false); tv.setText("Sound is Stop"); } }); Button change=(Button)findViewById(R.id.changeActivity); change.setOnClickListener(new OnClickListener() { public void onClick(View v) { startActivity(new Intent(Class1.this,Class2.class)); } }); </code></pre> <p><strong>SAME FOR CLASS2</strong><br> HELPER CLASS CODE IS: </p> <pre><code>static boolean SoundON,SoundOFF; static MediaPlayer mp=new MediaPlayer(); public void loadAudio(Context context){ mp=MediaPlayer.create(context,R.raw.fullmoon); } public static void PlaySound(){ mp.start(); } public boolean setSoundON(boolean on){ SoundON=on; return SoundON; } public boolean setSoundOFF(boolean off){ SoundOFF=off; return SoundOFF; } public boolean isSoundON(){ return SoundON; } public boolean isSoundOFF(){ return SoundOFF; } public static void StopSound(){ mp.stop(); mp.release(); } </code></pre> <p>**NOW THE PROBLEM I AM GETTING IS WHEN I SHIFT FROM ON ACTIVITY TO ANOTHER APP CRASH AT THAT TIME PLZ HELP ME AND I WANT TO ON AND OFF THE SOUND ON CLICK OF OPTION MENU **<br> Thanks and Regards<br> RizN81</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload