When the MIDlet (Java program) is in the active state, the Application Manager (mobile phone operating system) will require the program to be suspended due to certain circumstances, such as sudden calls from a mobile phone or short messages. To save more system resources, the application manager first calls the pauseapp method to release some non-essential resources of the MIDlet, and then switches to the paused state. Therefore, the required code for resource release should be added in the pauseapp () method.
I use status parameters in the program to control the game process:
Private Static final int intgamewaiting =-1;
Private Static final int intgameready = 0;
Private Static final int intgameplaying = 1;
Private Static final int intgamepause = 2;
Private Static final int intgamewon = 3;
Private Static final int intgameend = 4;
Private Static final int intgamequit = 5;
Public int intgamestatus =-1;
Public int intgamestatusreserve =-1;
Protected void Startapp (){
If (intgamestatus = intgamepause)
{
Playcanvas = new clsplaycanvas ();
Playcanvas. setfullscreenmode (true );
Display. setcurrent (playcanvas );
Intgamestatus = intgamestatusreserve;
Playcanvas. continuegame ();
} Else {
Maincanvas = new clsmaincanvas ();
Maincanvas. setfullscreenmode (true );
Display. setcurrent (maincanvas );
}
}
Protected void pauseapp (){
// Isgamewaiting = true;
If (intgamestatus! = Intgamewaiting)
{
Playcanvas = NULL;
Intgamestatusreserve = intgamestatus;
Intgamestatus = intgamepause;
}
}
This ensures that the program returns to continue the game after it exits temporarily.
If necessary, you can design a pause canvas for the transition.