libgdx API

com.badlogic.gdx.backends.android
Class AndroidApplication

java.lang.Object
  extended by Activity
      extended by com.badlogic.gdx.backends.android.AndroidApplication
All Implemented Interfaces:
Application

public class AndroidApplication
extends Activity
implements Application

An implementation of the Application interface for Android. Create an Activity that derives from this class. In the Activity#onCreate(Bundle) method call the initialize(ApplicationListener, boolean) method specifying the configuration for the GLSurfaceView.

Author:
mzechner

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.badlogic.gdx.Application
Application.ApplicationType
 
Field Summary
protected  AndroidAudio audio
           
protected  AndroidFiles files
           
protected  boolean firstResume
           
protected  AndroidGraphics graphics
           
protected  Handler handler
           
protected  AndroidInput input
           
protected  ApplicationListener listener
           
protected  int logLevel
           
protected  java.util.List<java.lang.Runnable> runnables
           
protected  WakeLock wakeLock
           
 
Fields inherited from interface com.badlogic.gdx.Application
LOG_ERROR, LOG_INFO, LOG_NONE
 
Constructor Summary
AndroidApplication()
           
 
Method Summary
protected  FrameLayout.LayoutParams createLayoutParams()
           
protected  void createWakeLock(AndroidApplicationConfiguration config)
           
 void error(java.lang.String tag, java.lang.String message)
          Logs an error message to the console or logcat
 void error(java.lang.String tag, java.lang.String message, java.lang.Exception exception)
          Logs an error message to the console or logcat
 void exit()
          Exits the application.
 Audio getAudio()
          
 Files getFiles()
          
 Graphics getGraphics()
          
 Input getInput()
          
 long getJavaHeap()
           
 long getNativeHeap()
           
 Preferences getPreferences(java.lang.String name)
          Returns the Preferences instance of this Application.
 Application.ApplicationType getType()
          
 int getVersion()
          
 void initialize(ApplicationListener listener, AndroidApplicationConfiguration config)
          This method has to be called in the Activity#onCreate(Bundle) method.
 void initialize(ApplicationListener listener, boolean useGL2IfAvailable)
          This method has to be called in the Activity#onCreate(Bundle) method.
 View initializeForView(ApplicationListener listener, AndroidApplicationConfiguration config)
          This method has to be called in the Activity#onCreate(Bundle) method.
 View initializeForView(ApplicationListener listener, boolean useGL2IfAvailable)
          This method has to be called in the Activity#onCreate(Bundle) method.
 void log(java.lang.String tag, java.lang.String message)
          Logs a message to the console or logcat
 void log(java.lang.String tag, java.lang.String message, java.lang.Exception exception)
          Logs a message to the console or logcat
 void onConfigurationChanged(Configuration config)
           
protected  void onDestroy()
           
protected  void onPause()
           
protected  void onResume()
           
 void postRunnable(java.lang.Runnable runnable)
          Posts a Runnable on the main loop thread.
 void setLogLevel(int logLevel)
          Sets the log level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

graphics

protected AndroidGraphics graphics

input

protected AndroidInput input

audio

protected AndroidAudio audio

files

protected AndroidFiles files

listener

protected ApplicationListener listener

handler

protected Handler handler

firstResume

protected boolean firstResume

runnables

protected final java.util.List<java.lang.Runnable> runnables

wakeLock

protected WakeLock wakeLock

logLevel

protected int logLevel
Constructor Detail

AndroidApplication

public AndroidApplication()
Method Detail

initialize

public void initialize(ApplicationListener listener,
                       boolean useGL2IfAvailable)
This method has to be called in the Activity#onCreate(Bundle) method. It sets up all the things necessary to get input, render via OpenGL and so on. If useGL20IfAvailable is set the AndroidApplication will try to create an OpenGL ES 2.0 context which can then be used via Graphics.getGL20(). The GL10 and GL11 interfaces should not be used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the Graphics.isGL20Available() method. Uses a default AndroidApplicationConfiguration.

Parameters:
listener - the ApplicationListener implementing the program logic
useGL2IfAvailable - whether to use OpenGL ES 2.0 if its available.

initialize

public void initialize(ApplicationListener listener,
                       AndroidApplicationConfiguration config)
This method has to be called in the Activity#onCreate(Bundle) method. It sets up all the things necessary to get input, render via OpenGL and so on. If config.useGL20 is set the AndroidApplication will try to create an OpenGL ES 2.0 context which can then be used via Graphics.getGL20(). The GL10 and GL11 interfaces should not be used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the Graphics.isGL20Available() method. You can configure other aspects of the application with the rest of the fields in the AndroidApplicationConfiguration instance.

Parameters:
listener - the ApplicationListener implementing the program logic
config - the AndroidApplicationConfiguration, defining various settings of the application (use accelerometer, etc.).

createLayoutParams

protected FrameLayout.LayoutParams createLayoutParams()

createWakeLock

protected void createWakeLock(AndroidApplicationConfiguration config)

initializeForView

public View initializeForView(ApplicationListener listener,
                              boolean useGL2IfAvailable)
This method has to be called in the Activity#onCreate(Bundle) method. It sets up all the things necessary to get input, render via OpenGL and so on. If useGL20IfAvailable is set the AndroidApplication will try to create an OpenGL ES 2.0 context which can then be used via Graphics.getGL20(). The GL10 and GL11 interfaces should not be used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the Graphics.isGL20Available() method. Uses a default AndroidApplicationConfiguration.

Note: you have to add the returned view to your layout!

Parameters:
listener - the ApplicationListener implementing the program logic
useGL2IfAvailable - whether to use OpenGL ES 2.0 if its available.
Returns:
the GLSurfaceView of the application

initializeForView

public View initializeForView(ApplicationListener listener,
                              AndroidApplicationConfiguration config)
This method has to be called in the Activity#onCreate(Bundle) method. It sets up all the things necessary to get input, render via OpenGL and so on. If config.useGL20 is set the AndroidApplication will try to create an OpenGL ES 2.0 context which can then be used via Graphics.getGL20(). The GL10 and GL11 interfaces should not be used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the Graphics.isGL20Available() method. You can configure other aspects of the application with the rest of the fields in the AndroidApplicationConfiguration instance.

Note: you have to add the returned view to your layout!

Parameters:
listener - the ApplicationListener implementing the program logic
config - the AndroidApplicationConfiguration, defining various settings of the application (use accelerometer, etc.).
Returns:
the GLSurfaceView of the application

onPause

protected void onPause()

onResume

protected void onResume()

onDestroy

protected void onDestroy()

getAudio

public Audio getAudio()

Specified by:
getAudio in interface Application
Returns:
the Audio instance

getFiles

public Files getFiles()

Specified by:
getFiles in interface Application
Returns:
the Files instance

getGraphics

public Graphics getGraphics()

Specified by:
getGraphics in interface Application
Returns:
the Graphics instance

getInput

public Input getInput()

Specified by:
getInput in interface Application
Returns:
the Input instance

getType

public Application.ApplicationType getType()

Specified by:
getType in interface Application
Returns:
what Application.ApplicationType this application has, e.g. Android or Desktop

getVersion

public int getVersion()

Specified by:
getVersion in interface Application
Returns:
the Android API level on Android or 0 on the desktop.

getJavaHeap

public long getJavaHeap()
Specified by:
getJavaHeap in interface Application
Returns:
the Java heap memory use in bytes

getNativeHeap

public long getNativeHeap()
Specified by:
getNativeHeap in interface Application
Returns:
the Native heap memory use in bytes

getPreferences

public Preferences getPreferences(java.lang.String name)
Description copied from interface: Application
Returns the Preferences instance of this Application. It can be used to store application settings across runs.

Specified by:
getPreferences in interface Application
Parameters:
name - the name of the preferences, must be useable as a file name.
Returns:
the preferences.

postRunnable

public void postRunnable(java.lang.Runnable runnable)
Description copied from interface: Application
Posts a Runnable on the main loop thread.

Specified by:
postRunnable in interface Application
Parameters:
runnable - the runnable.

onConfigurationChanged

public void onConfigurationChanged(Configuration config)

exit

public void exit()
Description copied from interface: Application
Exits the application. This will cause a call to pause() and dispose() some time in the loadFuture, it will not immediately finish your application!

Specified by:
exit in interface Application

log

public void log(java.lang.String tag,
                java.lang.String message)
Description copied from interface: Application
Logs a message to the console or logcat

Specified by:
log in interface Application

log

public void log(java.lang.String tag,
                java.lang.String message,
                java.lang.Exception exception)
Description copied from interface: Application
Logs a message to the console or logcat

Specified by:
log in interface Application

error

public void error(java.lang.String tag,
                  java.lang.String message)
Description copied from interface: Application
Logs an error message to the console or logcat

Specified by:
error in interface Application

error

public void error(java.lang.String tag,
                  java.lang.String message,
                  java.lang.Exception exception)
Description copied from interface: Application
Logs an error message to the console or logcat

Specified by:
error in interface Application

setLogLevel

public void setLogLevel(int logLevel)
Description copied from interface: Application
Sets the log level. Application.LOG_NONE will mute all log output. Application.LOG_ERROR will only let messages issued with Application.error(String, String) through. Application.LOG_INFO will let all messages though, either logged via Application.error(String, String) or Application.log(String, String).

Specified by:
setLogLevel in interface Application
Parameters:
logLevel - Application.LOG_NONE, Application.LOG_ERROR, Application.LOG_INFO.

libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)