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(); } });
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++; } });
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)