gameCanvas的创建,跳过了无限循环的线程
代码是
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Nyaong extends MIDlet implements Runnable {
private GameCanvas gameCanvas;
private Display display;
// private ProgressBar bar;
private splashCanvas splash = null;
private boolean play = true;
private Thread t = null;
public Nyaong() {
display = Display.getDisplay(this);
t = new Thread(this);
}
public void startApp() {
if(play){
t.start();
play = false;
}else{
gameCanvas.showNotify();
}
}
public void pauseApp() {
gameCanvas.hideNotify();
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void pause(int timer) {
try {
Thread.yield();
Thread.sleep(timer);
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
splash = new splashCanvas(this);
while (!splash.logoEnd) {// 在未执行完开场logo之前此线程瘫痪
System.out.println("oooooooooooo");
pause(100);
}
splash = null;
if (splash == null)
{
System.out.println("test");
gameCanvas = new GameCanvas(this);
gameCanvas.setState( GameCanvas.STATE_LOGO );
// gameCanvas.startCanvas();
display.setCurrent(gameCanvas);
gameCanvas.run();
}
}
}
如果注释掉
if (splash == null)
{
System.out.println("test");
gameCanvas = new GameCanvas(this);
gameCanvas.setState( GameCanvas.STATE_LOGO );
// gameCanvas.startCanvas();
display.setCurrent(gameCanvas);
gameCanvas.run();
}
部分,splash = new splashCanvas(this);部分能够正常执行,不注释掉,就会内存溢出,但是循环写的是正确的(多人检查很多遍了),请问大牛们,是什么原因时程序跳过了无限循环部分
------解决方案--------------------------------------------------------
showNotify();是否反复调用了?