Use pauseapp to control the temporary exit of the Java program on the mobile phone.

Source: Internet
Author: User
Tags playcanvas

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.