i wrote an android code for recording including some threads in it. but i need to limit the thread execution time to 1 second. though this is my first time with threads i tried using TimerTask as in here :timerTask or handler
but its not working.
here's the code:
void playSound(){
        AudioTrack audioTrack= null;
        try{
        audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, generatedSnd.length, AudioTrack.MODE_STATIC);
        audioTrack.write(generatedSnd, 0, generatedSnd.length);
        audioTrack.play();
        Thread thr=new Thread(new Runnable(){
            public void run(){
                startRecording();
            }
        });
        thr.start();
        timer.schedule(new TimerTask(){
            int n=0;
            public void run(){
                stopRecording();
            }
        },1,1000);
        }
        catch(Exception e)
        {
            System.out.print(e);
        }
}
public void stopRecording()
{ mRecorder.stop();
mRecorder.release();
}
 
     
    