Handling a phone call/message in game [SOLVED]

Started by
6 comments, last by Multiverse 18 years ago
Hi, its me again. I've got a problem with my mobile phone game when I receive a call or text message while the game is running. I can answer the call, then return to the game, which is at the same point as when I left it, but then It goes back to the loading screen and seems to reinitialise. Now, I'm pretty sure thats down to my code, but I'll figure that out. What I really want to know is What resources should I destroy/release when a phone call is detected? I presume it is somewhat similar to a lost device in DirectX (alt-tabbing away from the game). Is it necissary/good practice for me to release all of my resources, and then re-initialise them after? Are there only certain 'volatile' resources that need to be released but others are safe to leave? [Edited by - Multiverse on April 3, 2006 3:56:17 AM]
Advertisement
When a MIDlet is restarted after a pause the MIDlet.startApp() method is called. If you haven't written startApp() so that it can handle restarting a paused game then that's probably your problem.

shmoove
depends largely on the phone. some will not call pauseApp/startApp and you'll have to rely on Canvas hideNotify/showNotify. moreover, some phones wont call pauseApp/hideNotify unless you Thread.sleep(1) per frame (they dont "want" to interrupt the jvm) - pretty few in the older generations.
Hi guys, I do have startApp and pauseApp functions implemented, i'm pretty sure that the code inside those functions is causing the problems.

What i really want to know is, should i be releasing anything when pauseApp is called? I heard somewhere that any 'Players' (for sound) should be released. I would like to know if there is anything else I should be handling in there in regards to resources. (images, m3g models etc)
normally on recieved call, startApp and pauseApp will be called,
maybe you could do sthg. like in this pseudo code below:


run(){  while(gamerunnin)  {    if (paused)      continue;     repaint();     // bla bla...  }}pauseApp(){   paused = true;}startApp(){   if ( paused )   {                Display.getDisplay( ... ).setCurrent( this ) ; //should restore display stuff here                paused = false;   }   else   {      //should init game   }}

.

I usually don't free any resources when the game is paused.

I use something similar to what Pro-Xex is doing:

public MyMIDlet {  private MyGameCanvas canvas;  void startApp() {    if (canvas == null) {      // first time, initialize      canvas = new MyGameCanvas();      canvas.start(); // starts main thread    }    else {      // if canvas != null it means we are unpausing      canvas.paused = false;    }  }  void pauseApp() {    canvas.paused = true;  }  // ...


The canvas has a run() method similar to the one in Pro-Xex's code.

werekarg's comments about phones not calling start/pauseApp should also be taken into consideration when porting.

shmoove
Quote:Original post by Multiverse
Hi guys, I do have startApp and pauseApp functions implemented, i'm pretty sure that the code inside those functions is causing the problems.

What i really want to know is, should i be releasing anything when pauseApp is called? I heard somewhere that any 'Players' (for sound) should be released. I would like to know if there is anything else I should be handling in there in regards to resources. (images, m3g models etc)


I just made a game that has it's gameloop in a separate thread and i just killed that thread when the game paused. Now i'm trying when the game pause i save the game and kill it, and then upon start i've implemented a resume function.
This is work in progress so i don't know if it will work or be accepted yet...
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.
Hi again guys, and thanks for the information. The problem I was having was to do with re-initialising everything when the phone call ended, since the code in startApp was being run again. So I just added a simple boolean to determine if its the first time startApp has been called or not.

I'll be sure to take hideNotify and showNotify into account when porting to certain phones as well. Thanks for that little tip!!

This topic is closed to new replies.

Advertisement