Thread, the Nightmare

Started by
2 comments, last by Goguigo 17 years, 6 months ago
:( Well, i meep working here fixing my app. I got a nokia manual where it talks about some threads. I quote the fellowing text:
[source code=javax]
class TestThread extends Thread
{
boolean running=true;
public void run()
{
while (running)
{
try
{
doSomething();
synchronized (this)
{
wait(1000);
}
}
catch (InterruptedException e)
{
}
}
}
public void kill()
{
synchronized (this)
{
notify();
running = false;
}
}
}

public void destroyApp(boolean unconditional)
{
myThread.kill();
try
{
// wait for the thread to actually die before continuing
thread.join();
}
catch (InterruptedException e)
{
// InterruptedException is never thrown
}
}
[/source code]

Well, my main issue here, with this code is that, how can i display a canvas? Cya
Advertisement
What are you talking about? This code has nothing to do with displaying a Canvas.
You need something more like this:

public class MyCanvas javax.microedition.lcdui.Canvas implements Runnable{public void keyPressed( int iKey ){}public void keyReleased( int iKey ){}public void paint( Graphics g ){}/**....insert the rest of canvas fcns .....**/int m_iState = 0;public void run(){while( m_iState != -1 ){// Do stuff in the thread heretry{Thread.sleep( 40 );}catch( Exception e ) {}}}


Does that answer your Q?
The thing i need to do is to create an application and kill it as clean as possible, to use the commandlistener from the cellphone. The code i posted at the beginning, dies in a very clean way, but i don't know how to implement a canvas there. The code you showed me Anonimous Poster (:P) i understand it very well, and many time's i had used it. Know what i mean? I dont know how to exit in a clean way.

:(

Thanks

This topic is closed to new replies.

Advertisement