Sign in to follow this  
Goguigo

Thread, the Nightmare

Recommended Posts

:( 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

Share this post


Link to post
Share on other sites
What are you talking about? This code has nothing to do with displaying a Canvas.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 here

try{
Thread.sleep( 40 );
}catch( Exception e ) {}
}
}



Does that answer your Q?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this