Mysteria

Monday, February 17, 2014

The life cycle of an app



Number
Category
Translate

  

9

What? 

French

A mobile application is different from PC software.

States of an application

Libgdx defined life cycle of an app that has multiple statements :

Created (the app has been run) ;
Suspended (the app is on pause for example you have receive a call or you clicked on home key) ;
Resumed (the app was launched while it was on pause);
Rendered ​​(the app is being used ) ;
Destroyed (the app has been closed)

A Method (function) for each state

With the ApplicationListener implemented we must define the methods that will be called whenever an event that changes the state of the application occurs.

package my.works.jeu;
import com.badlogic.gdx.ApplicationListener;
public class Jeu implements ApplicationListener {
            @Override
            public void create() {
            }
            @Override
            public void dispose() {
            }
            @Override
            public void pause() {
            }
            @Override
            public void render() {
            }
            @Override
            public void resize(int arg0, int arg1) {
            }
            @Override
            public void resume() {
            }
}

Or we can inherit from the abstract class ApplicationAdapter which itself implements ApplicationListener and it will not be necessarily to define all the methods

package my.works.jeu;
import com.badlogic.gdx.ApplicationListener;
public class Jeu extends ApplicationAdapter {
            public void create() {
            }
            public void pause() {
            }
            public void render() {
            }
}

This source code is the logic part of Libgdx project; this is where all the source code of our game/app is located

The called methods (functions)

Create () :
This method is called once the application is launched .
This method is called once the app is launched. This is where we will initialize our variable and instantiate our class that we need for our app / game

resize ( int width , int height) :
This method is called whenever the game screen (which is not in a paused state) is resized. It is always called just after the creation of the app (after the Create () methods). The parameters are the new width (in pixels) and the new height (in pixels) of the screen

render () :
Method called in an infinite loop.it is called several times per second depending on the device where our application is running.
All of the logic of the game / apps is constructed in this method, it is considered as the main loop.

pause ():
This method is useful only on Android (not on Desktop). It is called when the Home button is pressed or a phone call is received.
On the desktop this method is called just before the dispose() method, so just before the application is closed.
It is a good place to save the state of the game

resume () :
This method is called only on Android when the application which was on pause state get launched.

dispose () :
It is called when the app is closed. It is preceded by a pause () method

The following diagram illustrates the Libgdx life cycle of an app


 <<  Previous             

Main Menu   

Problems ?
If you have any comments or questions please post them in the comments section . Thank you for reading.



See also !

No comments:

Post a Comment