# InvokeOnUIThread(Action)

> Invokes delegate on Android application's UI thread.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.Android](/engine/6000.7/script-reference/unityengine/android.md)
* **Assembly:** UnityEngine.AndroidJNIModule

```csharp
public static void InvokeOnUIThread(Action action)
```

### Parameters

**** (\[Action]\(https\://learn.microsoft.com/dotnet/api/system.action)):&#x20;

### Remarks

**Note:** Certain Android Java functions, such as those related to the user interface can only be called on the UI thread.

Additional Resources: [Threads](https://developer.android.com/guide/components/processes-and-threads#Threads)

### Examples

```csharp
using System;
using UnityEngine;
using UnityEngine.Android;


public class JavaThreads: MonoBehaviour
{
    public void Start()
    {
        AndroidApplication.InvokeOnUIThread(() =>
        {
            // Button can only be added on UI thread
            using var button = new AndroidJavaObject("android.widget.Button", AndroidApplication.currentActivity);
            button.Call("setText", "Hello World");
            using var layoutParams = new AndroidJavaObject("android.widget.LinearLayout$LayoutParams", 500, 100);
            button.Call("setLayoutParams", layoutParams);
            AndroidApplication.unityPlayer
                .Call<AndroidJavaObject>("getFrameLayout")
                .Call("addView", button);
        });
    }
}
```
