Run into the same issue. What I'm doing is to not stop the thread and
restart it, but kill and rebuild it. I.e. kill the thread via:
boolean retry = true;
while (retry) {
try {
myThread.join();
retry = false;
} catch (InterruptedException e) {
}
}
When you need it again, create a new one and start it. Obviously this
is the crude way to do it, but with anything else I run into the same
illegal state issue. Interested if anyone has a better approach.
On May 6, 9:10 am, MSChoi <[email protected]> wrote:
> I made an application which has a thread for a notification
> progressbar.
>
> First time I started the thread, it works fine.
> But Second time I tried to start the thread again, the application
> stop with the exception.
>
> How can I solve this problem?
> Please give me any clue.
>
> [==========My thread code below==================]
> private class ProgressThread extends Thread {
> Handler mHandler;
> final static int STATE_DONE = 0;
> final static int STATE_RUNNING = 1;
> int outIncreamentPercent;
> int mState;
>
> ProgressThread(Handler h) {
> mHandler = h;
> }
>
> public void run() {
> int i = 0;
> setState(STATE_RUNNING);
> while (mState == STATE_RUNNING) {
>
> if (i > MAX_LOOP_COUNT) {
> setState(STATE_DONE);
> } else {
> if (i % 100 == 0) {
> outIncreamentPercent = (int)
> (((float) i / MAX_LOOP_COUNT) *
> 100);
>
> rv.setProgressBar(R.id.customProgressBar,
> 100,outIncreamentPercent, false);
>
> mNotificationManager.notify(NOTIFICATION_ID,notification);
>
> try {
> Thread.sleep(100);
> } catch (InterruptedException e) {
> // TODO Auto-generated catch
> block
> e.printStackTrace();
> }
> }
> }
> i = i + LOOP_INCREMENT;
> }
> super.run();
> } /* sets the current state for the thread, * used to stop the thread
> */
> public void setState(int state) {
> mState = state;
> }
>
> }
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group
> athttp://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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en