How to kill the thread?

Started by
0 comments, last by someone2 20 years ago
Hi, I am having a little weird problem! I am following the tutorial of MIDP 1.0 found here in gamedev.net The problem is.. how can i exit the program? returning from run() simply doesn''t make the program close! What is the way to exit the program? Thank you very much in advance...
Advertisement
Calling notifyDestroyed() should do it.

You may want to implement destroyApp() in such a way that it kills your thread. One way to do this:
public class myTest extends Midlet implements Runnable {  private boolean running;  private Thread t;  public void startApp() {    running = true;    t = new Thread(this);    t.start(); // hold on to a reference  }  public void run() {    while(running) {      // do something    }  }  public void destroyApp() {    running = false; // allow thread to break out of loop    t.join(); // wait until that thread finishes its last iteration    // any other cleanup here  }}

This topic is closed to new replies.

Advertisement