Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

AndroidJavaRunnable

Switch to Manual
public delegate AndroidJavaRunnable(): void;

Description

AndroidJavaRunnable is the Unity representation of a java.lang.Runnable object.

#pragma strict
// Pass execution context over to the Java UI thread.
function Start() {
	var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
	var activity = unityPlayer.GetStatic.<AndroidJavaObject>("currentActivity");
	activity.Call("runOnUiThread", new AndroidJavaRunnable(runOnUiThread));
}
function runOnUiThread() {
	Debug.Log("I'm running on the Java UI thread!");
}