[JavaME]解决来电问题(Incoming Call)
比如你的游戲正在進行中,卻突然一個電話,那么你能保證你的游戲不死機嗎?
解決來電問題,唯一需要做的就是重載Canvas的hideNotify()方法。
just like this:
?
protected?void?showNotify()?{??gameIsPaused?=?false;
}
?
protected?void?hideNotify()?{
??gameIsPaused?=?true;
}
?
private?void?theMainGameLoop()?{
??while?(gameIsRunning)?{
????if?(!gameIsPaused)?{
??????//?process?events?and?update?the?screen
????}
??}
}
不過,正像下面的帖子中談到的,Nokia 7650機型的問題是無法克服的,當你接電話時關閉了游戲,那么電話打完后你也無法啟動游戲了,除非重啟手機。
可供參考的帖子:
http://forum.java.sun.com/thread.jspa?forumID=76&threadID=581789
http://forum.java.sun.com/thread.jspa?forumID=76&threadID=376907
參考的資料《Nokia 中的暫停功能》:
實際上,當MIDlet 隱藏時,它總是處于暫停狀態。這在游戲應用軟件中尤其重要,因為,如果在游
戲被隱藏時沒有立刻暫停,游戲者可能會輸掉游戲。
可以用類Displayable 的方法isShown()或者類Canvas 或CustomItem 的方法 hideNotify() 來暫停MIDlet。
在Canvas 對象離開顯示屏后,方法hideNotify()將被立刻調用。在方法hideNotify()中創建
一個自動暫停機制,用來暫停線程、關閉計時器、保存重要數值等。參見下面的代碼范例:
protected void hideNotify()
{
//執行暫停時的操作
remainingTime = endTime – System.currentTimeMillis();
myThread.stop();
autoPaused = true;
repaint();
// Include a pause test in paint() method to check if paused
// paint a pause message on screen if autoPaused true
}
protected void paint(Graphics g)
{
// paint game screen here
if (autoPaused == true) {
// paint pause message
}
}
暫停之后的操作是繼續,故需要把Continue 選項顯示給用戶。
轉載于:https://www.cnblogs.com/zhengyun_ustc/archive/2005/11/16/incomingcall.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的[JavaME]解决来电问题(Incoming Call)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国3G标准开始欧洲征程 中兴通讯先拔头
- 下一篇: Visual C# 3.0 新特性概览