2
  1. Start Button...

        btn_start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                start_stop = true;
                thread.start();
                chronometer.setBase(SystemClock.elapsedRealtime() + timeWhenStopped);
                chronometer.start();
    
            }
        });
    
    1. Stop Button...

      btn_stop.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              chronometer.stop();
              // 변수에 저장된 값 초기화!!
              timeWhenStopped =0;
              start_stop=false;
              graph.removeAllSeries();
              data = 0;
              double[] resetted = new double[50];
              saving = resetted;
              if(thread !=null && thread.isAlive()) thread.interrupt();
              i++;
          }
      
      });
      
    2. And here is my thread in the same activity.

      runnable = new Runnable() {
      @Override
      public void run() {
          int j =i;
          if(!thread.interrupted()){
          for (int i = 0; i < 50; i++){
              if(start_stop){
                  runOnUiThread(new Runnable() {
      
                      @Override
                      public void run() {
                          addEntry();
                      }
                  });
                  try {
                      Thread.sleep(600); //여기서 속도 제어할 수 있나봄!
                  } catch (InterruptedException e) {
                      // manage error ...
                  }
              }
          }
      }
      }
      };
      thread = new Thread(runnable);
      

So what I'm going to do is. I want to draw some line graph started with button Start, and then stop and clear with stop button. and draw new graph again with start button. But every time I tried re-start , application shut-down with error..

" Thread already started... "

So I think I need to kill or stop thread by clicking Stop button.. and I've tried several ways ... recommended... around here and I couldn't solve yet.

help me please..

(+ and I'm quite new here,,, and,,, my English isn't perfect.. also it's my first question.. sorry for any mistakes. thanks)

fadden
  • 51,356
  • 5
  • 116
  • 166
  • Possible duplicate of [this](http://stackoverflow.com/questions/13538668/stop-thread-and-again-start-giving-illegalthreadstateexception-in-blackberry) – JavaGhost Oct 22 '15 at 17:47

0 Answers0