public final class CoronaEnvironment extends Object
CoronaActivity
as well as setting up
listeners for receiving events from the CoronaRuntime
.
All methods in this class are thread safe and can be called from any thread.
You cannot make instances of this class. Access is provided via static methods.
Modifier and Type | Method and Description |
---|---|
static void |
addRuntimeListener(CoronaRuntimeListener listener)
Adds a listener for receiving events from the
CoronaRuntime . |
static android.content.Context |
getApplicationContext()
Provides easy access to this application's
context.
|
static String |
getApplicationName()
Provides easy access to the application's name that is displayed to the end user.
|
static File |
getCachesDirectory(android.content.Context context)
Gets the path to Corona's caches directory.
|
static CoronaActivity |
getCoronaActivity()
Gets a reference to the currently active
CoronaActivity . |
static File |
getDocumentsDirectory(android.content.Context context)
Gets the path to Corona's documents directory.
|
static JavaFunction |
getLuaErrorHandler()
Gets the custom Lua error handler that was given to the
CoronaEnvironment.setLuaErrorHandler()
method. |
static File |
getTemporaryDirectory(android.content.Context context)
Gets the path to Corona's temporary directory.
|
static void |
removeRuntimeListener(CoronaRuntimeListener listener)
Removes the given listener that was added via the
addRuntimeListener() method. |
static void |
setLuaErrorHandler(JavaFunction handler)
Sets a custom handler for Lua errors, such as syntax or runtime errors.
|
static void |
showCoronaActivity(android.content.Context context)
Displays the
CoronaActivity window on screen. |
public static File getDocumentsDirectory(android.content.Context context)
This is the directory that Lua property "system.DocumentsDirectory" maps to.
This directory is located in internal storage.
public static File getTemporaryDirectory(android.content.Context context)
This is the directory that Lua property "system.TemporaryDirectory" maps to.
This directory is located in internal storage. Its files will be automatically deleted by the operating system if internal storage is low on space.
public static File getCachesDirectory(android.content.Context context)
This is the directory that Lua property "system.CachesDirectory" maps to.
This directory is located in internal storage. Its files will be automatically deleted by the operating system if internal storage is low on space.
public static void showCoronaActivity(android.content.Context context)
CoronaActivity
window on screen.
If the CoronaActivity
is currently suspended in the background, then this method will
bring it to the foreground.
DO NOT USE THIS API IN A CORONACARDS FOR ANDROID
PROJECT! There's no CoronaActivity
in
CoronaCards for Android so invoking this API will
crash your app!
public static CoronaActivity getCoronaActivity()
CoronaActivity
.CoronaActivity
object.
Returns null if the CoronaActivity
was never created, has been destroyed, or we're
using CoronaCards for Android.public static android.content.Context getApplicationContext()
public static String getApplicationName()
Added in daily build 2016.2869.
Returns an empty String
if
CoronaEnvironment.getApplicationContext()
is null.
public static JavaFunction getLuaErrorHandler()
CoronaEnvironment.setLuaErrorHandler()
method.Returns null if a custom error handler was not set. In this case, Corona will use its default error handling.
public static void setLuaErrorHandler(JavaFunction handler)
handler
- Reference to the custom Lua error handler.
This is a Lua function that is implemented in Java.
Set to null to use Corona's default error handler.
public static void addRuntimeListener(CoronaRuntimeListener listener)
CoronaRuntime
.listener
- The listener that will receive events. Cannot be null.CoronaRuntimeListener
public static void removeRuntimeListener(CoronaRuntimeListener listener)
addRuntimeListener()
method.listener
- The listener object to be removed by reference.CoronaRuntimeListener