Hi Gaurav,

Just set the property progressBar.setCanceleable(true) and call the method
progressBar.cancel() while stopping the thread.  It will stop the progress
bar.

Hope it helps....

Thanks!!

On Wed, Mar 23, 2011 at 11:39 AM, gaurav gupta <gaurav.gupta...@gmail.com>wrote:

> hi guys,
> in my application, m using a progrssbar that show the current progress of a
> song.i need to stop the song as well as progressbar too. progressbar should
> be reach at starting point and song should be stop.
>
> *
>
> class
> * myThread *extends* Thread *implements* Runnable{
>
> *private* *volatile* *boolean* paused = *false*;
>
> *private* *volatile* *boolean* finished = *false*;
>
> @Override
>
> *public* *void* run()
>
> {
>
> *while*(!finished){
>
> *while* (myProgress<100){
>
> *try*{
>
> Log.*d*(
> TAG, "Thread Starts");
>
> myProgress++;
>
> Log.*d*(
> "++++++++++++++++++++++",""+myProgress);
>
> seekbar.setProgress(myProgress);
>
> Thread.*sleep*(Long.*parseLong*(
> bundleDuration)/100);
>
> Log.*d*(
> TAG,"Passed thread.sleep");
>
> }
>
> *catch*(Throwable t){
>
> Log.*e*(
> "+++++++++++++++++++++++++++", "no duration");
>
> }
>
> *while*(paused && !finished){
>
> *try*{
>
> Thread.*sleep*(1000);
> //Busy wait - should really use wait/notify, but that's another lesson
>
> }
>
> *catch*(InterruptedException e){
>
> }
>
> }
>
> }
>
> }
>
> }
>
>
> ===============================================================================================
>
> m using a button stopbutton to stop this song which runs through a service
>
>
> *
>
> case
> * R.id.*buttonStop*:
>
> Log.*d*(
> TAG, "onClick: stopping srvice");
>
> stopService(
> *new* Intent(*this*, MyService.*class*));
>
> *if*(mt.isAlive())
>
> {
>
> mt.stopThread();// mt is the object of myThread class
>
> }
>
> =================================
>
> *StopThread function*
>
> *public* *synchronized* *void* stopThread(){
>
> *if*(mt != *null*){
>
> Thread mthread =
> mt;
>
> mt = *null*;
>
> mth dread.interrupt(); } }
>
> ===========================================
>
> please suggest me what to do??
>
> my progressbar's thread should be finished and its setduration must be
> zero.
>
> now its giving this in logcat and thread is continue in background
>
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276): FATAL EXCEPTION: main
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):
> java.lang.NullPointerException
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> com.gaurav.music.activity.AudioPlayerScreen.onClick(AudioPlayerScreen.java:190)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> android.view.View.performClick(View.java:2408)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> android.view.View$PerformClick.run(View.java:8816)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> android.os.Handler.handleCallback(Handler.java:587)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> android.os.Handler.dispatchMessage(Handler.java:92)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> android.os.Looper.loop(Looper.java:123)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> android.app.ActivityThread.main(ActivityThread.java:4627)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> java.lang.reflect.Method.invokeNative(Native Method)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> java.lang.reflect.Method.invoke(Method.java:521)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
> 03-23 11:35:16.070: ERROR/AndroidRuntime(276):     at
> dalvik.system.NativeStart.main(Native Method)
> 03-23 11:35:16.180: WARN/ActivityManager(59):   Force finishing activity
> com.hungama.myplay.activity/.AudioPlayerScreen
> 03-23 11:35:16.764: DEBUG/AudioPlayerScreen(276): Passed thread.sleep
>
> ============================================
>
> please help
>
> thanks in advance
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to