# AndroidJavaProxy

> This class can be used to implement any java interface. Any java vm method invocation matching the interface on the proxy object will automatically be passed to the c# implementation.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine](/engine/6000.6/script-reference/unityengine.md)
* **Assembly:** UnityEngine.AndroidJNIModule

```csharp
public class AndroidJavaProxy
```

## Remarks

Unity invokes the proxy method on the Java thread that calls the interface method, which isn't always the Unity main thread. To dispatch work to the Unity main thread, use [AndroidApplication.InvokeOnUnityMainThread](/engine/6000.6/script-reference/unityengine/android/androidapplication/invokeonunitymainthread.md), which blocks the calling thread until the delegate completes and has no effect in the Editor.

Android requires UI operations, such as showing a dialog, to run on the Android UI thread. The following example wraps the dialog call in `runOnUiThread` for that reason. You can also use [AndroidApplication.InvokeOnUIThread](/engine/6000.6/script-reference/unityengine/android/androidapplication/invokeonuithread.md) to dispatch to that thread.

**Note**: this API can be used from a custom thread, but requires that thread to be attached to JVM first. Refer to [AndroidJNI.AttachCurrentThread](/engine/6000.6/script-reference/unityengine/androidjni/attachcurrentthread.md).

## Examples

```csharp
// Opens an android date picker dialog and grabs the result using a callback.
using UnityEngine;
using System;

class ExampleClass : MonoBehaviour
{
    private static DateTime selectedDate = DateTime.Now;

    class DateCallback : AndroidJavaProxy
    {
        public DateCallback() : base("android.app.DatePickerDialog$OnDateSetListener") {}
        void onDateSet(AndroidJavaObject view, int year, int monthOfYear, int dayOfMonth)
        {
            selectedDate = new DateTime(year, monthOfYear + 1, dayOfMonth);
            // If you have no longer any uses for the object, it must be disposed to prevent a leak
            view.Dispose();
        }
    }

    void OnGUI()
    {
        if (GUI.Button(new Rect(15, 15, 450, 75), string.Format("{0:yyyy-MM-dd}", selectedDate)))
        {
            var activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
            activity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
            {
                new AndroidJavaObject("android.app.DatePickerDialog", activity, new DateCallback(), selectedDate.Year, selectedDate.Month - 1, selectedDate.Day).Call("show");
            }));
        }
    }
}
```

## Fields

| Value                                                                                          | Description                              |
| ---------------------------------------------------------------------------------------------- | ---------------------------------------- |
| [javaInterface](/engine/6000.6/script-reference/unityengine/androidjavaproxy/javainterface.md) | Java interface implemented by the proxy. |

## Methods

| Method                                                                               | Description                                                                                                                                                                                                                                                                 |
| ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [equals](/engine/6000.6/script-reference/unityengine/androidjavaproxy/equals.md)     | The equivalent of the java.lang.Object `equals()` method.                                                                                                                                                                                                                   |
| [hashCode](/engine/6000.6/script-reference/unityengine/androidjavaproxy/hashcode.md) | The equivalent of the java.lang.Object `hashCode()` method.                                                                                                                                                                                                                 |
| [Invoke](/engine/6000.6/script-reference/unityengine/androidjavaproxy/invoke.md)     | Called by the java vm whenever a method is invoked on the java proxy interface. You can override this to run special code on method invocation, or you can leave the implementation as is, which will convert argument array to AndroidJavaObject\[] and call other Invoke. |
| [toString](/engine/6000.6/script-reference/unityengine/androidjavaproxy/tostring.md) | The equivalent of the java.lang.Object `toString()` method.                                                                                                                                                                                                                 |
