• Advertisement
Sign in to follow this  

Handling a phone call/message in game [SOLVED]

This topic is 4345 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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
}
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement