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 damiant · Aug 22, 2013 at 05:21 AM · javaandroidpluginjni

Calling a java method from a second thread is not working

I have this little function calling a java (android) method:

 public static void Compose(string initialText, string url, string image, Action<bool> callback) {        
     Loom.RunAsync(() => {
         AndroidJNI.AttachCurrentThread();
         bool rs;
         using (AndroidJavaClass jc = new AndroidJavaClass("com.beavl.android.ShareTools")) { 
            rs = jc.CallStatic<bool>("share", initialText, url, image);             
         }             
         Loom.QueueOnMainThread(() => {callback(rs);});
     });                    
 }

Note: Loom is a multithreading library that worked perfectly so far for me. It's here.

And the function just doesn't work, it does nothing as if it was never called.
If I remove the Loom parts of the function, so I call it from the main thread, it does work.

I have a log on the first line of the function to be sure when it's called or not.

Any idea why i'm getting this behaviour?

Comment
Add comment · Show 3
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 fafase · Aug 22, 2013 at 05:24 AM 0
Share

It looks like C# but you mention Java and the main thread so I reckon you are in the wrong place. This is for Unity that does not use Java. You better go to StackOverflow which takes all kind of issues (including Unity). I close the answer but if for some reasons I would be wrong I will open it again.

avatar image whydoidoit · Aug 22, 2013 at 06:23 AM 0
Share

Unity uses Java on Android!

avatar image Bunny83 · Aug 22, 2013 at 07:05 AM 0
Share

You should also take a look at your device log ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by whydoidoit · Aug 22, 2013 at 06:31 AM

What is the return value of AndroidJNI.AttachCurrentThread();? Can you Debug.Log it?

Comment
Add comment · Show 1 · 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 damiant · Aug 22, 2013 at 01:05 PM 0
Share

@whydoidoit: AndroidJNI.AttachCurrentThread() result is 0. As a note, I Debug.Log it before calling the java function and in the logcat nothing is printed after that. @fafase: I'm calling an android java function from C#. @Bunny83: I'm using adb logcat!

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

18 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

Related Questions

Now that Unity 4.1.2 broke the Android plugin examples, what do you use to learn them? 1 Answer

How use the Java Native Interface in Unity outside of Android? 1 Answer

AndroidJava and Implementing java.util.List 0 Answers

CHANGING MANIFESTS DOES NOT WORK!! CommandInvokationFailure: Unable to merge android manifests. See the Console for more details 0 Answers

BroadcastReceiver onReceive not called from custom Unity android plugin 1 Answer


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