APIdia Launch Partner
Top Description Inners Fields Methods
com.badlogic.gdx

public Interface Application

Imports
com.badlogic.gdx.utils.Clipboard

An Application is the main entry point of your project. It sets up a window and rendering surface and manages the different aspects of your application, namely Graphics, Audio, Input and Files. Think of an Application being equivalent to Swing's JFrame or Android's Activity.

An application can be an instance of any of the following:

Each application class has it's own startup and initialization methods. Please refer to their documentation for more information.

While game programmers are used to having a main loop, libGDX employs a different concept to accommodate the event based nature of Android applications a little more. You application logic must be implemented in a ApplicationListener which has methods that get called by the Application when the application is created, resumed, paused, disposed or rendered. As a developer you will simply implement the ApplicationListener interface and fill in the functionality accordingly. The ApplicationListener is provided to a concrete Application instance as a parameter to the constructor or another initialization method. Please refer to the documentation of the Application implementations for more information. Note that the ApplicationListener can be provided to any Application implementation. This means that you only need to write your program logic once and have it run on different platforms by passing it to a concrete Application implementation.

The Application interface provides you with a set of modules for graphics, audio, input and file i/o.

Graphics offers you various methods to output visuals to the screen. This is achieved via OpenGL ES 2.0 or 3.0 depending on what's available an the platform. On the desktop the features of OpenGL ES 2.0 and 3.0 are emulated via desktop OpenGL. On Android the functionality of the Java OpenGL ES bindings is used.

Audio offers you various methods to output and record sound and music. This is achieved via the Java Sound API on the desktop. On Android the Android media framework is used.

Input offers you various methods to poll user input from the keyboard, touch screen, mouse and accelerometer. Additionally you can implement an InputProcessor and use it with Input#setInputProcessor(InputProcessor) to receive input events.

Files offers you various methods to access internal and external files. An internal file is a file that is stored near your application. On Android internal files are equivalent to assets. On the desktop the classpath is first scanned for the specified file. If that fails then the root directory of your application is used for a look up. External files are resources you create in your application and write to an external storage. On Android external files reside on the SD-card, on the desktop external files are written to a users home directory. If you know what you are doing you can also specify absolute file names. Absolute filenames are not portable, so take great care when using this feature.

Net offers you various methods to perform network operations, such as performing HTTP requests, or creating server and client sockets for more elaborate network programming.

The Application also has a set of methods that you can use to query specific information such as the operating system the application is currently running on and so forth. This allows you to have operating system dependent code paths. It is however not recommended to use these facilities.

The Application also has a simple logging method which will print to standard out on the desktop and to logcat on Android.

Author
mzechner

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Application.ApplicationType

Enumeration of possible Application types

Field Summary

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int

Method Summary

Modifier and TypeMethod and Description
public void
addLifecycleListener(LifecycleListener listener)

Adds a new LifecycleListener to the application.

public void
debug(String tag, String message)

Logs a debug message to the console or logcat

public void
debug(String tag, String message, Throwable exception)

Logs a debug message to the console or logcat

public void
error(String tag, String message)

Logs an error message to the console or logcat

public void
error(String tag, String message, Throwable exception)

Logs an error message to the console or logcat

public void
exit()

Schedule an exit from the application.

public ApplicationListener
public ApplicationLogger
public Audio
getAudio()

Returns: the Audio instance

public Clipboard
public Files
getFiles()

Returns: the Files instance

public Graphics
getGraphics()

Returns: the Graphics instance

public Input
getInput()

Returns: the Input instance

public long
getJavaHeap()

Returns: the Java heap memory use in bytes

public int
getLogLevel()

Gets the log level.

public long
getNativeHeap()

Returns: the Native heap memory use in bytes

public Net
getNet()

Returns: the Net instance

public Preferences

Returns:

the preferences.
getPreferences
(String
the name of the preferences, must be useable as a file name.
name
)

Returns the Preferences instance of this Application.

public Application.ApplicationType
getType()

Returns: what ApplicationType this application has, e.g. Android or Desktop

public int
getVersion()

Returns: the Android API level on Android, the major OS version on iOS (5, 6, 7, ..), or 0 on the desktop.

public void
log(String tag, String message)

Logs a message to the console or logcat

public void
log(String tag, String message, Throwable exception)

Logs a message to the console or logcat

public void
postRunnable(Runnable
the runnable.
runnable
)

Posts a Runnable on the main loop thread.

public void
public void
setApplicationLogger(ApplicationLogger applicationLogger)

Sets the current Application logger.

public void
setLogLevel(int logLevel)

Sets the log level.

Field Detail

LOG_DEBUGback to summary
public static final int LOG_DEBUG
LOG_ERRORback to summary
public static final int LOG_ERROR
LOG_INFOback to summary
public static final int LOG_INFO
LOG_NONEback to summary
public static final int LOG_NONE

Method Detail

addLifecycleListenerback to summary
public void addLifecycleListener(LifecycleListener listener)

Adds a new LifecycleListener to the application. This can be used by extensions to hook into the lifecycle more easily. The ApplicationListener methods are sufficient for application level development.

debugback to summary
public void debug(String tag, String message)

Logs a debug message to the console or logcat

debugback to summary
public void debug(String tag, String message, Throwable exception)

Logs a debug message to the console or logcat

errorback to summary
public void error(String tag, String message)

Logs an error message to the console or logcat

errorback to summary
public void error(String tag, String message, Throwable exception)

Logs an error message to the console or logcat

exitback to summary
public void exit()

Schedule an exit from the application. On android, this will cause a call to pause() and dispose() some time in the future, it will not immediately finish your application. On iOS this should be avoided in production as it breaks Apples guidelines

getApplicationListenerback to summary
public ApplicationListener getApplicationListener()
Returns:ApplicationListener

the ApplicationListener instance

getApplicationLoggerback to summary
public ApplicationLogger getApplicationLogger()
Returns:ApplicationLogger

the current ApplicationLogger

getAudioback to summary
public Audio getAudio()
Returns:Audio

the Audio instance

getClipboardback to summary
public Clipboard getClipboard()
getFilesback to summary
public Files getFiles()
Returns:Files

the Files instance

getGraphicsback to summary
public Graphics getGraphics()
Returns:Graphics

the Graphics instance

getInputback to summary
public Input getInput()
Returns:Input

the Input instance

getJavaHeapback to summary
public long getJavaHeap()
Returns:long

the Java heap memory use in bytes

getLogLevelback to summary
public int getLogLevel()

Gets the log level.

getNativeHeapback to summary
public long getNativeHeap()
Returns:long

the Native heap memory use in bytes

getNetback to summary
public Net getNet()
Returns:Net

the Net instance

getPreferencesback to summary
public Preferences getPreferences(String name)

Returns the Preferences instance of this Application. It can be used to store application settings across runs.

Parameters
name:String

the name of the preferences, must be useable as a file name.

Returns:Preferences

the preferences.

getTypeback to summary
public Application.ApplicationType getType()
Returns:Application.ApplicationType

what ApplicationType this application has, e.g. Android or Desktop

getVersionback to summary
public int getVersion()
Returns:int

the Android API level on Android, the major OS version on iOS (5, 6, 7, ..), or 0 on the desktop.

logback to summary
public void log(String tag, String message)

Logs a message to the console or logcat

logback to summary
public void log(String tag, String message, Throwable exception)

Logs a message to the console or logcat

postRunnableback to summary
public void postRunnable(Runnable runnable)

Posts a Runnable on the main loop thread. In a multi-window application, the Gdx#graphics and Gdx#input values may be unpredictable at the time the Runnable is executed. If graphics or input are needed, they can be copied to a variable to be used in the Runnable. For example:

final Graphics graphics = Gdx.graphics;

Parameters
runnable:Runnable

the runnable.

removeLifecycleListenerback to summary
public void removeLifecycleListener(LifecycleListener listener)

Removes the LifecycleListener.

setApplicationLoggerback to summary
public void setApplicationLogger(ApplicationLogger applicationLogger)

Sets the current Application logger. Calls to log(String, String) are delegated to this ApplicationLogger

setLogLevelback to summary
public void setLogLevel(int logLevel)

Sets the log level. LOG_NONE will mute all log output. LOG_ERROR will only let error messages through. LOG_INFO will let all non-debug messages through, and LOG_DEBUG will let all messages through.

Parameters
logLevel:int

LOG_NONE, LOG_ERROR, LOG_INFO, LOG_DEBUG.

com.badlogic.gdx back to summary

public final Enum Application.ApplicationType

extends Enum<Application.ApplicationType>
Class Inheritance

Enumeration of possible Application types
Author
mzechner

Field Summary

Modifier and TypeField and Description
public static final Application.ApplicationType
public static final Application.ApplicationType
public static final Application.ApplicationType
public static final Application.ApplicationType
public static final Application.ApplicationType
public static final Application.ApplicationType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Application.ApplicationType
public static Application.ApplicationType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

Androidback to summary
public static final Application.ApplicationType Android
Appletback to summary
public static final Application.ApplicationType Applet
Desktopback to summary
public static final Application.ApplicationType Desktop
HeadlessDesktopback to summary
public static final Application.ApplicationType HeadlessDesktop
iOSback to summary
public static final Application.ApplicationType iOS
WebGLback to summary
public static final Application.ApplicationType WebGL

Constructor Detail

ApplicationTypeback to summary
private ApplicationType()

Method Detail

valueOfback to summary
public static Application.ApplicationType valueOf(String name)
valuesback to summary
public static Application.ApplicationType[] values()