For example, if your game is in progress, but suddenly a phone call occurs, can you ensure that your game will not crash?
To solve the call problem, the only thing that needs to be done is to reload the canvas enoworkflow () method of canvas.
Just like this:
Boolean Gameispaused;
Protected Void Showpolicy () {Gameispaused= False;
}
Protected Void Hidenotify () {
Gameispaused= True;
}
Private Void Themaingameloop () {
While (Gameisrunning) {< br> If ( ! gameispaused) {< br> /// process events and update the screen
}
}
}
However, as mentioned in the following post, the problem with the Nokia 7650 model cannot be overcome. When you close the game while answering the phone, you cannot start the game after the phone is called, unless you restart your phone.
Reference posts:
Http://forum.java.sun.com/thread.jspa? Forumid = 76 & threadid = 581789.
Http://forum.java.sun.com/thread.jspa? Forumid = 76 & threadid = 376907.
reference:
In fact, when the MIDlet is hidden, it is always paused. This is especially important in game applications, because players may lose the game if the game is not immediately suspended when the game
is hidden.
you can use the displayable-like method isshown (), canvas-like, or customitem-like method hidenovel () to pause the MIDlet.
after the canvas object leaves the display, the hidenotify () method is called immediately. Create
an automatic pause mechanism in the hidenotify () method to pause threads, disable timers, and save important values. See the following Code example:
protected void hidenoworkflow ()
{< br> // when the pause is executed
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
}< br> protected void paint (Graphics g)
{< br> // paint game screen Here
If (autopaused = true) {
// paint pause message
}< BR >}< br> after the pause, the operation continues, therefore, the continue option must be displayed to the user.