05-15-2012 12:53 AM
i need to develope a program of thread.
i need two buttons
on these two buttons i need to perform some task.
when i press start..the somethings start happening.
when i press stop all the thread stop.
and againg i press start ..i should start
Solved! Go to Solution.
05-15-2012 01:56 AM
A simple (and very naive) way to do it is:
1. On a clicking the start button, you check if the thread is not null and you start it.
2. In the thread, hold a while loop with a flag which was set to true (on step #1).
2. When clicking on the stop button, set the flag value to false so the loop would stop and the thread would finish its work.
Hope that helps,
05-15-2012 01:59 AM
Thanks for reply.
Like this or some else
public void threadStart()
Thread thread = new Thread()
boolean active = true;
public void run()
int i =1;
05-15-2012 02:09 AM
exactly my problem is i want to show "Hello"on my device with press start button.
until i dont press stop . it hello should displayed regular after every second like this.
but after press stop it should stop...but
if i press start again it should start
05-15-2012 02:33 AM
Here are couple of options:
1. Let your thread run consistency and only do your work if your active flag set to true.
2. After the thread is stop, re-initiate it:
myThread = new MyThread();
05-15-2012 05:30 AM