2009-08-02 25 views
2

MIDlet調用notifyDestroyed()方法來通知AMS它要轉到銷燬狀態。一旦AMS收到這個通知,它就會認爲MIDlet在調用notifyDestroyed()方法之前已經完成了所有的資源清除過程。J2ME notifyDestroyed()

因此,它會殺死MIDlet而不是調用destroyApp()方法。

回答

1

看來最好的做法是在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 
} 
1

在notifyDestroyed()被調用後,AMS肯定不會調用destroyApp()。

當運行正確的MIDlet時,一個不正確的AMS可能會導致堆棧溢出情況。