Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by liortal · May 26, 2014 at 09:40 AM · androidandroidjavaobjectjni

What is the difference between AndroidJavaClass.Call and AndroidJavaObject.Call

According to the documentation:

AndroidJavaObject is the Unity representation of a generic instance of java.lang.Object. AndroidJavaClass is the Unity representation of a generic instance of java.lang.Class.

Also, AndroidJavaClass derives from AndroidJavaObject.

What is the difference between these two:

AndroidJavaClass ajc = new AndroidJavaClass("someclass"); AndroidJavaObject ajo = new AndroidJavaObject("someclass");

ajo.Call("Method"); // Calls an instance method using the jobject reference

ajc.Call("Method"); // Calls an instance method using the class reference (?? doesn't make sense)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by liortal · May 28, 2014 at 08:36 PM

Answering my own question - after doing some research, it seems that the two methods are the same.

AndroidJavaClass inherits from AndroidJavaObject, but does not override the Call method. This means the Call method for this class is exactly the same one as for AndroidJavaObject.

Note that when using an AndroidJavaClass, using the Call method has no effect, since no object instance was initialized (one can only use CallStatic or the generic CallStatic).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Andres-Fernandez · Jun 12, 2014 at 06:37 AM 0
Share

I am currently researching on that since I'm getting stuck in a mail sending problem. From what I have read in the docs (althoug I haven't tried it yet), you could be able to use AndroidJavaClass.Call on a static class pretty much as you can do it with a regular C# class that doesn't derive from $$anonymous$$onoBehaviour. Am I too wrong? I'm not a Java coder (much less an experienced android developer).

avatar image Julijana · Jun 06, 2018 at 11:17 PM 0
Share

Finally some good stuff.

avatar image
0

Answer by tyoc213 · Aug 06, 2014 at 03:09 PM

From http://www.j2megame.com/html/xwzx/ty/2609.html

This will not create another com.unity3d.player.UnityPlayer Activity (of some sort)... it will let you directly access the class static methods without create "new instance of the class".

 AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
  // jni.FindClass("com.unity3d.player.UnityPlayer"); 
  AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"); 
  // jni.GetStaticFieldID(classID, "Ljava/lang/Object;"); 
  // jni.GetStaticObjectField(classID, fieldID); 
  // jni.FindClass("java.lang.Object"); 


This will create a new java string on VM.

 AndroidJavaObject jo = new AndroidJavaObject("java.lang.String", "some_string"); 
  // jni.FindClass("java.lang.String"); 
  // jni.GetMethodID(classID, "<init>", "(Ljava/lang/String;)V"); 
  // jni.NewStringUTF("some_string"); 
  // jni.NewObject(classID, methodID, javaString);


As I see any other case is the same usage or equivalent. Basically use AndroidJavaClass when going to call static methods and not want to create a new instance, NOTE that you can also access static methods from AndroidJavaObject created instance.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image liortal · Aug 06, 2014 at 05:35 PM 1
Share

But i was specifically interested in whats the different between both classes' Call method.

avatar image drhmiri liortal · Jun 20, 2017 at 01:55 PM 0
Share

@liortal Are these two methods really different? For example, the following two posts that detail writing plug-ins using "AndroidJavaObject" and "UnityPlayer": this and this

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AndroidJavaClass. Call returns null ptr. 1 Answer

AndroidJavaObject.Call fails with 'method not found' 1 Answer

Call non-static method (from subclass) in Java from Unity 1 Answer

Getting native Android String constants via JNI broken in Unity 2019.2.0? 3 Answers

Returning byte array from Java/Android 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges