Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6973027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:03:19+00:00 2026-05-27T17:03:19+00:00

I am working on Android game and I am providing options menu to Turn

  • 0

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

Class 1(main code i try is)

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));  

                    }  
                 });    

SAME FOR CLASS2
HELPER CLASS CODE IS:

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();         
    }  

**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 **
Thanks and Regards
RizN81

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:03:19+00:00Added an answer on May 27, 2026 at 5:03 pm

    I would go for a Singleton class that could manage all the sounds in your activity. I haven’t previously done in Android, but on C++, and I’ve seen in other examples (here and here) that actually support my idea.

    A Singleton is accessible from everywhere in your application and more importantly, there’s only one instance per application, which will let you configure any sound globally.

    What those links and me are telling is that having a single class that manages every sound in your game will help you:

    1. simplify sound calls (you can call every sound from a HashMap (for example) by YourSoundManager.getInstance().play("soundName"); and stop them by YourSoundManager.getInstance().stop("soundName");, or simply copy-pasting the examples above to have a little more control in speed and sounds) by facading the calls and,
    2. control any sound, just like you had a big mixing console, except it is done using nothing but code 🙂

    From those examples it depends on what you want to do to mute your game. Either stopping all the sounds, or putting their volume down. I’d go for stopping them at first, as it’s the simplest approach.

    EDIT:

    If you want to stop a sound when switching from an activity to another one, you can still use the singleton approach.

    You can override the onResume() method so it plays the sound you are willing to use. Also check that this sound isn’t playing by looking up at a HashMap that could contain any playing sound (or use other more familiar tactics). I’ll write you some code that may not be working to you (as it depends on your final approach and how you manage sounds)

    @Override
    public void onResume()
    {
        if(! SoundManager.getInstance().isPlaying("thisStageSound") ) //if it's already playing, do not stop it!
        {
            SoundManager.getInstance().stopAllSounds();
            SoundManager.getInstance().playSound("thisStageSound");
        }
        super.onResume();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an android game with OpenGL, and I have a game update
I am developing a game for android an i'm working on the menu screen
I am working on a game in Android and I have Bitmap objects being
I'm working in a game for Android, but is the same game that exist
Ive been working on multiplayer android game that sends locally stored data to a
I'm working on an android game and have been considering my main game loop.
I have been working on an Android game for the past 6 months or
I have a been working on a game for Android and debugging it on
I was working on an android game and read that the best practice is
Hi I'm new to android development and working on a game. I currently have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.