Fiz uma aplicação que na hora de fechar ela chama uma tela, quando eu clico no botão que tem na tela o programa realmente fecha, mas tem vezes que o programa trava, alguém saberia dizer o que pode estar acontecendo?
Chamada para a tela de fechar:
protected void close(boolean unconditional) {
System.out.println("[" + this.mainThread.getName() + "] DestroyApp.");
//new AdViewClose(this, "Advertising");
System.out.println("[" + this.mainThread.getName() + "] Total of Threads: " + this.mainThread.activeCount());
Advertising ad = new Advertising(this, false);
ad.start();
if (this.mainThread.activeCount() > 1) {
synchronized (this) {
try {
System.out.println("[" + this.mainThread.getName() + "] Wait...");
this.wait();
} catch (InterruptedException ex) {
ex.printStackTrace();
this.notifyDestroyed();
}
}
}
System.out.println("[" + this.mainThread.getName() + "] Finish app.");
}
Classe que exibe a tela de fechar:
[code]
public AdViewClose(MIDlet midlet, String title) {
super(title);
System.out.println("[" + THREAD_NAME + “] Star advertising close.” );
System.out.println("[" + THREAD_NAME + “] Midlet: " + midlet);
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
this.midlet = (FrontContainer) midlet;
System.out.println(”[" + THREAD_NAME + “] Print screem close.”);
this.addCommand(new Command(“Sair”, Command.OK, 1));
ImageBase imageBase = new ImageBase();
imageBase.open();
byte[] image = null;
try {
image = imageBase.getImage();
imageBase.close();
imageBase.delete();
this.append(Image.createImage(image, 0, image.length));
this.setCommandListener(this);
System.out.println("[" + THREAD_NAME + “] Before display close.”);
Display.getDisplay(this.midlet).setCurrent(this);
System.out.println("[" + THREAD_NAME + “] After display close.”);
} catch(Exception e) {
e.printStackTrace();
}
}
public void commandAction(Command c, Displayable d) {
System.out.println("[" + THREAD_NAME + "] Click close.");
if (c.getCommandType() == Command.OK) {
synchronized(this.midlet) {
this.midlet.notifyAll();
this.midlet.destroyAppSuper(true);
}
}
}
}[/code]
A classe Advertising é uma thread que chama a classe AdViewClose.