internal JavaObject(IntPtr jobject) : this()
        {
            if (jobject == IntPtr.Zero)
            {
                throw new Exception("JavaObject: have tried to init JavaObject with null ptr!");
            }

            IntPtr objectClass = JNISafe.GetObjectClass(jobject);

            mObject = CreateGlobalRef(jobject);
            mClass  = CreateGlobalRef(objectClass);

            JNISafe.DeleteLocalRef(objectClass);
        }
        internal JavaObject(params object[] args)
        {
            if (args == null)
            {
                args = new object[0];
            }
            mClass = CreateGlobalRef(FindClass(GetClass(GetType())));
            string sign = GetSignature(null, args);

            jvalue[] jniArgArray = ConstructArgArray(args);
            try {
                IntPtr num = JNISafe.NewObject(mClass, AndroidJNIHelper.GetConstructorID(mClass, sign), jniArgArray);
                mObject = CreateGlobalRef(num);
                JNISafe.DeleteLocalRef(num);
            }
            finally {
                AndroidJNIHelper.DeleteJNIArgArray(args, jniArgArray);
            }
        }
        public static IntPtr ConvertToJNIArray <TElement>(Array array)
        {
            System.Type elementType = typeof(TElement);

            System.Diagnostics.Debug.Assert(elementType != null, "elementType != null");
            if (elementType.IsSubclassOf(typeof(JavaObject)))
            {
                int      length1 = array.GetLength(0);
                IntPtr[] array2  = new IntPtr[length1];
                IntPtr   class1  = FindClass(GetClass(elementType));
                IntPtr   type    = IntPtr.Zero;
                for (int index = 0; index < length1; ++index)
                {
                    JavaObject obj = array.GetValue(index) as JavaObject;
                    if (obj != null)
                    {
                        array2[index] = obj.RawObject;
                        IntPtr rawClass = obj.RawClass;
                        if (type != rawClass)
                        {
                            type = !(type == IntPtr.Zero) ? class1 : rawClass;
                        }
                    }
                    else
                    {
                        array2[index] = IntPtr.Zero;
                    }
                }
                IntPtr num = JNISafe.ToObjectArray(array2, type);
                JNISafe.DeleteLocalRef(class1);

                return(num);
            }

            return(AndroidJNIHelper.ConvertToJNIArray(array));
        }