MIDlet 调用 notifyDestroyed() 方法来通知 AMS 它想要进入 Destroyed 状态。一旦 AMS 收到此通知,它将假定 MIDlet 在调用 notifyDestroyed() 方法之前已经完成了所有资源清除过程。
因此,它会杀死 MIDlet 而不是调用 destroyApp() 方法。
在调用 notifyDestroyed() 之后,AMS 肯定不会调用 destroyApp()。
执行此操作的不正确 AMS 在运行正确的 MIDlet 时可能最终导致堆栈溢出。
在 notifyDestroyed() 之前调用 destroyApp() 似乎是最佳做法。
try {
// Call destroyApp to release resources
destroyApp(false);
// Arrange for the MIDlet to be destroyed
notifyDestroyed();
} catch (MIDletStateChangeException ex) {
// MIDlet does not want to close
}