[JavaME]解决来电问题(Incoming Call)

news/2024/6/18 4:39:47

比如你的游戏正在进行中,却突然一个电话,那么你能保证你的游戏不死机吗?
解决来电问题,唯一需要做的就是重载Canvas的hideNotify()方法。

just like this:

boolean gameIsPaused;
 
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 选项显示给用户。





http://www.niftyadmin.cn/n/3649691.html

相关文章

JavaScript函数式编程介绍:融合与转换

介绍 (Introduction) Fusion and transduction may be the most practical tools I’ve picked up in my time studying Functional Programming. They’re not tools I use every day, nor are they strictly necessary, but, they completely changed the way I think about …

【javaEE面试题(四)线程不安全的原因】【1. 修改共享数据 2. 操作不是原子性 3. 内存可见性 4. 代码顺序性】

4. 多线程带来的的风险-线程安全 (重点) 4.1 观察线程不安全 static class Counter {public int count 0;void increase() {count;} } public static void main(String[] args) throws InterruptedException {final Counter counter new Counter();Thread t1 new Thread(()…

CentOS 7安装谷歌浏览器

一、安装谷歌浏览器 1、使用root登录终端 su root2、配置下载yum源 cd /etc/yum.repos.d vim google-chrome.repo添加以下内容 [google-chrome] namegoogle-chrome baseurlhttp://dl.google.com/linux/chrome/rpm/stable/$basearch enabled1 gpgcheck1 gpgkeyhttps://dl-ss…

SymbianOS Error -3606问题解决了

CMNET"SymbianOsError -3606"“KErrGenConnDatabaseDefaultUndefined -3606 "No Internet accounts have been set up. Set up an account in Control panel." ”CMNET

web应用程序体系结构_为不同的操作系统和体系结构构建Go应用程序

web应用程序体系结构In software development, it is important to consider the operating system and underlying processor architecture that you would like to compile your binary for. Since it is often slow or impossible to run a binary on a different OS/archit…

我的个人博客正式关联第三方博客平台

第三方博客平台简介 第三方博客指的是不要求自己有域名,空间,服务器,仅在大型门户网址注册就可运行的博客平台。 这类博客有新浪,搜狐,和讯,网易等。第三方博客现在已经成为更多网络爱好者发布自己心情&am…