How to stop my progressbar that runs using thread in android?
<p>This is a part of a project, main focus is when I want to stop the thread then my progressbar should reach of starting point and thread must be stop.
But it's not happening in my demo. I can't use Async Task in this. How can I stop the thread in this particular example? Thread.stop,notify,boolean flags are not working.</p>

<pre><code>public class AudioPlayer2 extends BaseScreen implements OnClickListener  {
// private static final String TAG = "ServicesDemo";
  Button buttonPause, buttonStart, buttonStop,buttonForward,buttonBackward;
//String uri;
private final String TAG = AudioPlayer2.class.getSimpleName();
private String uri, albumArtUri;
private MediaPlayer mp;
VideoView vv; 
ImageView iv, ivAlbumArt;
Uri albumImageUri;
ArrayList&lt;Track&gt; tracks;
static Uri sArtworkUri;
public LinearLayout addvideo;
private String songName, albumName;
private TextView tvName, tvAlbum;
private static int current_song;
private static long album_id;
public ProgressBar seekbar;
public int myProgress=0;
public MyService myservice;
//public static double duration=0;
String bundleDuration;
myThread mt;
Thread t;
private volatile boolean flag;
String nextDuration=null;
long seekbarProgress=0;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.audio);
    seekbar = (ProgressBar)findViewById(R.id.seekbar);

   /* myservice = this.myService;
   myservice.AP2 = AudioPlayer2.this;*/
    uri = this.getIntent().getExtras().getString("song_uri");
    buttonStart = (Button) findViewById(R.id.buttonStart);
    buttonStop = (Button) findViewById(R.id.buttonStop);
    buttonPause = (Button) findViewById(R.id.buttonPause);
    tracks = dbManager.getInstance().getAllSongs(AudioPlayer2.this);

    buttonForward = (Button) findViewById(R.id.buttonforward);
    buttonBackward = (Button) findViewById(R.id.buttonbackward);
    //=========================================================================================
    sArtworkUri = Uri.parse("content://media/external/audio/albumart");
        Uri path = Uri.parse(uri);
    current_song=this.getIntent().getExtras().getInt("current_song");
    albumArtUri = this.getIntent().getExtras().getString("album_art");
    bundleDuration = this.getIntent().getExtras().getString("duration");
    Log.d("+++++++++++++++++++Duration", bundleDuration);
    Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
     album_id = Long.parseLong(this.getIntent().getStringExtra("album_id"));
    int id = Integer.parseInt(this.getIntent().getStringExtra("album_id"));

    //Toast.makeText(AudioPlayer2.this, ""+Long.parseLong(bundleDuration), Toast.LENGTH_SHORT).show();
      seekbar.setProgress(0);

    albumImageUri = ContentUris.withAppendedId(sArtworkUri, album_id);
    ivAlbumArt = (ImageView) findViewById(R.id.album_art);

    songName = this.getIntent().getStringExtra("song_name");
    albumName = this.getIntent().getStringExtra("album_name");

    tvName = (TextView) findViewById(R.id.tv_name);
    tvAlbum = (TextView) findViewById(R.id.tv_album);
    if (songName != null) {
        tvName.setText(songName);
    }

    if (albumName != null) {
        tvAlbum.setText(albumName);
    }



    if (DataManager.getInstance().getOnPausedSong()=="y"){

        if(DataManager.getInstance().getPausedSongName()==songName){

        buttonStart.setVisibility(View.GONE);
        buttonPause.setVisibility(View.VISIBLE);
    }
    }

     stopService(new Intent(this, MyService.class));
     Intent intent = new Intent(this,MyService.class);
        Bundle b = new Bundle();
        b.putString("song_uri",uri );
        intent.putExtras(b);
        startService(intent);
         mt = new myThread();
         t = new Thread(mt);
         mt.start();
        buttonStart.setVisibility(View.GONE);
        buttonPause.setVisibility(View.VISIBLE);

        //=======================================================================================
  buttonStop.setVisibility(View.GONE);


    buttonStart.setOnClickListener(this);
    buttonPause.setOnClickListener(this);
    buttonForward.setOnClickListener(this);
    buttonBackward.setOnClickListener(this);
    buttonStop.setOnClickListener(this);
    buttonStart.performClick();  
  }
  public void onClick(View src) {
    switch (src.getId()) {
    case R.id.buttonStart:
        if(DataManager.getInstance().getSongPause()=="y"){
            myService.player.start();
            DataManager.getInstance().setSongPause("n");
            buttonStart.setVisibility(View.GONE);
            buttonPause.setVisibility(View.VISIBLE);
            if(mt.paused==true){
                mt.unPauseProgressBar();

            }
        }else{
    stopService(new Intent(this, MyService.class));
        DataManager.getInstance().setSong_uri(uri); 
        Intent intent = new Intent(this,MyService.class);
        Bundle b = new Bundle();
        b.putString("song_uri",uri );
        intent.putExtras(b);
        startService(intent);
        buttonStart.setVisibility(View.GONE);
        buttonPause.setVisibility(View.VISIBLE);
        DataManager.getInstance().setOnPausedSong("y");
        DataManager.getInstance().setPausedSongName(songName);
            }

        break;
    case R.id.buttonStop:
      Log.d(TAG, "onClick: stopping srvice");
      stopService(new Intent(this, MyService.class));
      buttonStart.setVisibility(View.VISIBLE);
        buttonPause.setVisibility(View.GONE);
        mt=null;
        seekbar.setProgress(0);
        mt.stopProgressBar();
        //mt.destroy();

        //mt.notify();


 break;
    case R.id.buttonforward:

         stopService(new Intent(this, MyService.class));
         current_song++;
        FetchAllMusic fetchAllMusic = new FetchAllMusic();
        fetchAllMusic.execute();
       flag=false;
       myProgress=0;
       bundleDuration=tracks.get(current_song).getDuration();
    Toast.makeText(this, tracks.get(current_song++).getDuration(), Toast.LENGTH_LONG).show();
       //   Log.d("aaaaaaaaaaaaaaa", nextDuration);
       //seekbar.setProgress(0);
        myThread mt2=new myThread();
       mt2.start();
        //new Thread(myThread).start();


            break;
    case R.id.buttonbackward:
          Log.d(TAG, "onClick: stopping service");
          stopService(new Intent(this, MyService.class));
          if(current_song&gt;0){   
          current_song--;
           }
            FetchAllMusic fetchAllMusic2 = new FetchAllMusic();
            fetchAllMusic2.execute();

          break;
    case R.id.buttonPause:

          buttonStart.setVisibility(View.VISIBLE);
            buttonPause.setVisibility(View.GONE);
            myService.player.pause();

            DataManager.getInstance().setSongPause("y");
            DataManager.getInstance().setWantsToPlaySong(false);
            DataManager.getInstance().setOnPausedSong("n");
            DataManager.getInstance().setPausedSongName(songName);

            mt.pauseProgressBar();
        }
  }

  public void getDuration(String duration){
      Log.d(TAG,"BeforeToast");
      Log.d(TAG,"After Toast");
      seekbarProgress = Long.parseLong(duration);
      seekbar.setProgress(1);
      Log.d(TAG,"Before thread.start");
      Log.d(TAG,"After thread.start");
  }

  class myThread extends Thread implements Runnable{
        //      long duration=DataManager.getInstance().getSong_duration();
    //long value=duration/100;
          private volatile boolean paused = false;
          private volatile boolean finished = false;
                    @Override
                public void run()
                {
                        if(flag==false)
                        {
                            mt.currentThread().notify();
                        }
                    {
                    while(!finished){
                while (myProgress&lt;100){
                try{
                    Log.d(TAG, "Thread Starts");
                //  myHandle.sendMessage(myHandle.obtainMessage());
                    myProgress++;
                    Log.d("+++++++++AA+++++++++++++",""+bundleDuration);
                    seekbar.setProgress(myProgress);
                Thread.sleep(Long.parseLong(bundleDuration)/100);
                Log.d(TAG,"Passed thread.sleep");

                }
                catch(Throwable t){
                    Log.e("+++++++++++++++++++++++++++", "no duration");
                }
                   while(paused &amp;&amp; !finished){
                        try{
                            Thread.sleep(1000); //Busy wait - should really use wait/notify, but that's another lesson
                        }
                        catch(InterruptedException e){

                        }

                }
                    }       
                }
                    }                           //=============================     
                }
                 public synchronized void pauseProgressBar(){
                        paused = true;
                    }

                    public synchronized void unPauseProgressBar(){
                        paused = false;
                        //call notify() here when you switch to wait/notify.
                    }

                    public synchronized void stopProgressBar(){
                        finished = true;
                       stop();
                       mt = null;
                        notify();
                       //  destroy();

                    }
                };
</code></pre>
