I avoid the exception with using of narrow-down variable scope.
Actually my friend suggest it me.
<previous code>
public class study004statuswithprogressbar extends Activity {
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (event.getUnicodeChar() - '0') {
case 1:
//Some Code Here
if ( progressIncrementthread.isAlive() == false )
{
progressIncrementthread.start();
}
}
ProgressThread progressIncrementthread = new
ProgressThread(uploadProgressBarHandler);
private class ProgressThread extends Thread {
}
}
<new code>
public class study004statuswithprogressbar extends Activity {
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (event.getUnicodeChar() - '0') {
case 1:
//Some Code Here
ProgressThread progressIncrementthread = new
ProgressThread(uploadProgressBarHandler);
if ( progressIncrementthread.isAlive() == false )
{
progressIncrementthread.start();
}
}
//Move it to switch
//ProgressThread progressIncrementthread = new
ProgressThread(uploadProgressBarHandler);
private class ProgressThread extends Thread {
}
}
It works!!
I think this is very smart way to avoid the problem.
But I still want to solve the problem instead of using variable scope.
Does anybody can do it?
Please suprise me. =)
On 5월6일, 오후6시59분, tobias429 <[email protected]> wrote:
> 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
> 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