Game Development Reference
In-Depth Information
The application module
The application module can be accessed through Gdx.app . It gives you access to the
logging facility, a method to shutdown gracefully, persist data, query the Android
API version, query the platform type, and query the memory usage.
Logging
LibGDX employs its own logging facility. You can choose a log level to filter what
should be printed to the platform's console. The default log level is LOG_INFO . You
can use a settings file and/or change the log level dynamically at runtime using the
following code:
Gdx.app.setLogLevel(Application.LOG_DEBUG);
The available log levels are as follows:
LOG_NONE : This prints no logs and the logging is completely disabled
LOG_ERROR : This prints error logs only
LOG_INFO : This prints error and info logs
LOG_DEBUG : This prints error, info, and debug logs
To write an info, debug, or error log to the console, use the following listings:
Gdx.app.log("MyDemoTag", "This is an info log.");
Gdx.app.debug("MyDemoTag", "This is a debug log.");
Gdx.app.error("MyDemoTag", "This is an error log.");
Shutting down gracefully
You can tell LibGDX to shut down the running application. The framework will then
stop the execution in the correct order as soon as possible and completely deallocate
any memory that is still in use, freeing both Java and the native heap. Use the
following listing to initiate a graceful shutdown of your application:
Gdx.app.exit();
You should always do a graceful shutdown when you want to terminate
your application. Otherwise, you will risk creating memory leaks, which
is a really bad thing. On mobile devices, memory leaks will probably
have the biggest negative impact due to their limited resources. Note
that in an Android device, it will call the pause() and dispose()
functions sometime later and won't immediately finish the application.
 
Search WWH ::




Custom Search