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

  • Home
  • SEARCH
  • 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 9031939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:51:23+00:00 2026-06-16T07:51:23+00:00

I’m creating a simple click counter android app, sound is played when a button

  • 0

I’m creating a simple click counter android app, sound is played when a button is clicked and the count is also saved when leaving the count screen and then returning to it.

I have encountered a problem with the mute button. When I click it, it mutes the whole application rather than just that particular gui screen (activity).

  1. First issue is that the mute button mutes the sound for the whole app, and I only need to mute for that activity.

  2. Second issue is that when you click mute button and come out of the screen, then go back, then try to unmute – it does not unmute the sound.

Was thinking the resolution to this is that we take the mute button out of the SharedPreferences save instance state – if this is possible…

Here is my code so far, if you can guide me on how to achieve the above that would be great. Thanks.

public class wazeefa extends Activity {

    //Count Button
    TextView txtCount;
    ImageView image;
    Button btnCount;
    Button wmute;
    Button wreset;
    public static int count = 0;
    SharedPreferences app_preferences;
    MediaPlayer mpButtonClick;
    AudioManager audioManager;
    public static boolean mutestatus = false;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // The activity is being created.
        setContentView(R.layout.wazeefa);


        audioManager =
                (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        //SAVE COUNT
        app_preferences = this.getSharedPreferences("myPrefscount", MODE_WORLD_READABLE);


        count = app_preferences.getInt("count", 0);

        txtCount = (TextView) findViewById(R.id.wcount);
        txtCount.setText("This app has been started " + count + " times.");

        image = (ImageView) findViewById(R.id.imageview);

        txtCount = (TextView) findViewById(R.id.wcount);
        txtCount.setText("This app has been started " + count + " times.");

        //Button SOUND AND COUNT
        mpButtonClick = MediaPlayer.create(this, R.raw.bubble);
        //RESET Button
        wreset = (Button) findViewById(R.id.wreset);

        txtCount = (TextView) findViewById(R.id.wcount);
        txtCount.setText(String.valueOf(count));

        btnCount = (Button) findViewById(R.id.wclick);

        wmute = (Button) findViewById(R.id.wmute);

        btnCount.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                count++;
                if (count > 50) count = 0;
                image.setImageResource(R.drawable.duroodimage);
                if (count > 0) image.setImageResource(R.drawable.duroodimage);
                if (count > 9) image.setImageResource(R.drawable.zikrimage);
                if (count > 39) image.setImageResource(R.drawable.duroodimage);
                txtCount.setText(String.valueOf(count));
                mpButtonClick.start();
            }
        });

        wreset.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                count = 0;
                image.setImageResource(R.drawable.duroodimage);
                ;
                txtCount.setText("0");
                SharedPreferences.Editor editor = app_preferences.edit();
                editor.putInt("count", count);
                editor.commit();
            }
        });


        wmute.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if (!mutestatus) {
                    mutestatus = true;
                    audioManager.setMode(AudioManager.MODE_IN_CALL);
                    audioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, true);
                    Log.v("'test....", "" + mutestatus);
                } else {
                    mutestatus = false;
                    audioManager.setMode(AudioManager.MODE_NORMAL);
                    audioManager.setStreamSolo(AudioManager.STREAM_VOICE_CALL, false);
                    Log.v("'test....", "" + mutestatus);
                }
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        // save count value here

        SharedPreferences.Editor editor = app_preferences.edit();
        editor.putInt("count", count);
        editor.commit();

    }
}
  • 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-06-16T07:51:24+00:00Added an answer on June 16, 2026 at 7:51 am

    You are saving the preferences on the application level, make it Activity specific, i.e. Implement mute functionality for the activity not the application.

    Edit

    See your objective is some what to mute and unmute (loquent) the audio, Preferences can be saved in three ways.

    1) Preferences can be retrieved only by a single activity.
    2 )Preferences can be shared and retrieved among all activities within the application.
    3)Preferences can be shared and retrieved through all applications on the device.

    In your case, Saving Activity-level preferences:

    SharedPreferences prefs=getPreferences(Context.MODE_PRIVATE);
            SharedPreferences.Editor editor=prefs.edit();
            editor.putString("pref 1", "some text");
    
            editor.commit();
    

    We get a SharedPreferences object by calling getPreferences(int mode) method which takes an integer value as a parameter, the mode value can be one of the following:

    Context.MODE_PRIVATE (0): a file creating mode that makes the created file only accessible by applications with the same user ID (access the file from the same application context, will desctribe later).
    Context.MODE_WORLD_READABLE (1): file mode makes the file readable from other applications.
    Context.MODE_WORLD_WRITEABLE (2): file mode allows other applications to write to the file.
    Then we get an instance of SharedPreferences.Editor and write the preference value with editor.putString(String key, String value) method.
    shared preferences allows you to insert preferences using the following methods:

    editor.putBoolean(String key, boolean value).
    editor.putFloat(String key,float value).
    editor.putInt(String key, int value).
    editor.putLong(String key, long value)
    editor.putString(String key, String value)
    

    Then we call edit.commit() to save the preferences to the file. commit returns a boolean indicating the result of saving, true if successful and false if failed.

    Reading preferences values:
    To read preferences values:

    SharedPreferences prefs=getPreferences(Context.MODE_PRIVATE);
    String val=prefs.getString("pref 1", "some text");
    We use sharedpreferences.getString(String key, String defaultValue) (or get boolean/float/int) to return the value stored with a specific key or defaultValue if not found.
    

    Source

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app with both english and french support. The app requests
I have a reasonable size flat file database of text documents mostly saved in
I am using Paperclip to handle profile photo uploads in my app. They upload

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.