The Application interface provides various methods to query properties of the run-time environment.

Getting the Application Type

Sometimes it is necessary to special case specific parts of an application depending on the platform it is running on. The Application.getType() method returns the platform the application is currently running on:

  1. switch (Gdx.app.getType()) {
  2. case Android:
  3. // android specific code
  4. break;
  5. case Desktop:
  6. // desktop specific code
  7. break;
  8. case WebGl:
  9. // HTML5 specific code
  10. break;
  11. default:
  12. // Other platforms specific code
  13. }

On Android, one can also query the Android version the application is currently running on:

  1. int androidVersion = Gdx.app.getVersion();

This will return the SDK level supported on the current device, e.g., 3 for Android 1.5.

Memory Consumption

For debugging and profiling purposes it is often necessary to know the memory consumption, for both the Java heap and the native heap:

  1. long javaHeap = Gdx.app.getJavaHeap();
  2. long nativeHeap = Gdx.app.getNativeHeap();

Both methods return the number of bytes currently in use on the respective heap.

Prev | Next