progress bar along with timer in android
<p>i am recording voice in my android app so the recording is ok.now i want to record for certain amount of time so using the Timer().schedule method in order to stop that recording and that also working fine and stopping recording after the given time.now i have progress bar to show the recording progress,the progress thing is also ok but the recording is finishing before the progress bar complete.to find the recording status putted  textview and changing while recording finished.so the textview text say <em>RECORDING FINISHED</em> but the progress bar still in progress.</p>

<p>i am starting the recording on oncreate() method of the activity</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    setContentView(R.layout.displaypic);
             startrecording();
</code></pre>

<p>after that  starting the progress bar using asynctask
new Timer().schedule(new TimerTask() {</p>

<pre><code>        @Override
        public void run() {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    mytask.execute(totalsec);

                }
            });

        }
    }, 1000);
</code></pre>

<p>here i am using the timer to start the progress after 1 sec.</p>

<p>here is the code which will stop the recording after given time.</p>

<pre><code>new Timer().schedule(new TimerTask() {

            @Override
            public void run() {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub
                        myaudiorecoreder.stop();
                        myaudiorecoreder.reset();
                        myaudiorecoreder.release();
                        setRecordstatus(false);
                        myaudiopath.setAudiofile(audiofile);
                        // Toast.makeText(getApplicationContext(),
                        // "RECORDING STOP", 0).show();
                        myrecordtextview.setText("RECORDING FINISHED");
                        //myprogress_bar.setVisibility(View.INVISIBLE);
                    }
                });

            }
        }, setrecordtime);
</code></pre>

<p>as you can see i am setting the text for myrecordtextview which will show that recording finished.but in real the output varies.</p>

<p>here is the code for progress bar updating and displaying</p>

<pre><code>private class ProgressTask extends AsyncTask&lt;Long, Integer, Void&gt; {
        @Override
        protected void onPreExecute() {
            counter = (int) (totalsec / 1000) * 100;
            myprogress_bar.setMax(counter);
            myrecordtextview.setTextColor(Color.parseColor("#ff0000"));
            myrecordtextview.setText("RECORDING....");
            myprogress_bar.setVisibility(View.VISIBLE);
        }

        @Override
        protected Void doInBackground(Long... params) {
            check_status = isRecordstatus();

            for (int i = 0; i &lt;= counter; i += 100) {
                try {

                    // if async task is not cancelled, update the progress

                    publishProgress(i);
                    SystemClock.sleep(1000);

                } catch (Exception e) {
                    Log.e("Error", e.toString());
                }

            }

            return null;
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            myprogress_bar.setProgress(values[0]);
        }

        @Override
        protected void onPostExecute(Void result) {
            // if(check_status==false){
            // //myrecordtextview.setText("RECORDING FINISHED");
            myprogress_bar.setVisibility(View.INVISIBLE);
            // }

        }
</code></pre>

<p>here the totalsec is the given time to finish the recording and progress bar progress also
a little help will be very much appreciate.
if any thing required please let me know.
thanks</p>
