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 8181137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:25:16+00:00 2026-06-07T00:25:16+00:00

Well I can start the thread when I press togglebutton to ON and it

  • 0

Well I can start the thread when I press togglebutton to ON and it works fine, that thread is to start audiorecord and audiotrack.
But I cannot stop the thread when I put togglebutton OFF… because I cannot do thread.stop… What I want to do is just stop audiorecord and audiotrack… If there is any way to start/stop them w/o making thread will be also fine.
Also, as I cannot stop thread, when I do togglebutton ON – OFF – ON, it makes an error because can’t start a thread 2 times.

  • 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-07T00:25:18+00:00Added an answer on June 7, 2026 at 12:25 am

    The stop() method of Thread has been Deprecated (because it inherently unsafe) and java provides an alternative way to stop a Thread. Its a very simple approach, as described in this official link:

    http://docs.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html

    Did you try making the isRecording variable global and then altering its state:

     isRecording = false;
    
     Thread thread;
    
     Runnable r = new Runnable() {
    public void run() {
        isRecording = true;
        android.os.Process
                .setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
        int buffersize = AudioRecord.getMinBufferSize(8000,
                AudioFormat.CHANNEL_CONFIGURATION_MONO,
                AudioFormat.ENCODING_PCM_16BIT);
        arec = new AudioRecord(MediaRecorder.AudioSource.MIC, 11025,
                AudioFormat.CHANNEL_CONFIGURATION_MONO,
                AudioFormat.ENCODING_PCM_16BIT, buffersize);
        int bufferzize = AudioTrack.getMinBufferSize(11025,
                AudioFormat.CHANNEL_CONFIGURATION_MONO,
                AudioFormat.ENCODING_PCM_16BIT);
        atrack = new AudioTrack(AudioManager.STREAM_MUSIC, 11025,
                AudioFormat.CHANNEL_CONFIGURATION_MONO,
                AudioFormat.ENCODING_PCM_16BIT, bufferzize,
                AudioTrack.MODE_STREAM);
        atrack.setPlaybackRate(11025);
        byte[] buffer = new byte[buffersize];
        if (arec.getState() == AudioRecord.STATE_INITIALIZED)
            arec.startRecording();
        if (atrack.getState() == AudioTrack.STATE_INITIALIZED)
            atrack.play();
        while (isRecording) {
            arec.read(buffer, 0, buffersize);
            atrack.write(buffer, 0, buffer.length);
        }
    }
    
    };
    
    tbs = (ToggleButton) findViewById(R.id.tbS);
    tbs.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                thread = new Thread(r)
                thread.start();
                } else {
              isRecording = false;
              thread = null;
            }
    
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`v made my webpart that works well (I can add it to page and
I have a menu working fairly well but can't figure out how to make
I hope I can explain this well enough so that you can understand the
Is there a well-designed method that can run my ruby program from anywhere? I
Its a well known fact that a static method can work only on static
Well I am trying to learn the java MVC pattern, but I can't understand
Can i create successfully a timer clock on a thread? i'm creating one but
I am trying to parallel a classic map-reduce problem (which can parallel well with
Well, I must be brain-damaged, because I can't find the java source for Sun's
Well, I'm completely new to JavaScript. Can you please tell me what type of

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.