• 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 /
  • Help Room /
avatar image
0
Question by kingandroid · Oct 06, 2015 at 05:21 AM · androidandroidjavaobject

[BUG] AndroidJavaObject getStringArrayExtra() crash

Hi, I have the following code

 AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
 
         //the previous intent that started this app
         AndroidJavaObject intent = null;
         try
         {
             intent = ca.Call<AndroidJavaObject>("getIntent"); //no exception ever happened(?)
         }
         catch (Exception e)
         {
             logText.text += e.ToString();
             successGetIntent = false;
         }

         try 
         {
         var strings = intent.Call<string[]>("getStringArrayExtra","KEY"); //this causes crash even in try catch if there no such extra send to this app
         }
         catch (Exception e)
         { //do smthng}

         up.Dispose();
         ca.Dispose();
         intent.Dispose();

the problem is, everytime I call getStringArrayExtra it will always crash and stop the unity, I cant even catch the exception. Is there anyway to solve this?

Thanks

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

1 Reply

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

Answer by kingandroid · Oct 06, 2015 at 11:15 PM

I solved this by myself and marked it as bug.

When I changed getStringArrayExtra to getStringExtra it is now not crashing (Obviously I change the sender sending string, instead of sending string[] previously)

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 Bunny83 · Oct 07, 2015 at 10:27 AM 0
Share

That makes not much sense to "mark is as bug". Since it seems to work with "getStringExtra" the error was clearly on your side. "getStringArrayExtra" searches for a stored string array with the key "$$anonymous$$EY". Since it works with getStringExtra the key you're looking for seems to be a string and not a string array.

You're using the JNI interface that Java provides. If an exception occurs on the native Java side, Android will kill your app. Such an exception can't be caught from the managed side of $$anonymous$$ono.

It's also bad style to call Dispose "manually". Use "using" statements

     string val = "";
     using(AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
     using(AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity"))
     using(AndroidJavaObject intent = ca.Call<AndroidJavaObject>("getIntent"))
     {
         val = intent.Call<string>("getStringExtra","$$anonymous$$EY");
     } // at this point all 3 objects will be disposed in reverse order

You might want to look up getStringArrayExtra and what it actually does.

avatar image kingandroid Bunny83 · Oct 12, 2015 at 10:46 PM 0
Share

Like I said, when I'm using getStringArrayExtra i'm sending string[] and if the app can find the string[] it working perfectly. When it can't it just crashes - which is not the case when I'm sending string and get it with getStringExtra, if there is no string found it won't make the app crash.

Also in my newest version I'm using 'using'

but anyway thanks for the reply

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

35 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Android UnityPlayer attribute "currentActivity" returns null 1 Answer

How turn On/Off android display backlight using C# only in Unity3d 1 Answer

Android getUuidForPath of shared/external storage volumes 0 Answers

Why is USB Storage being detected only in some android devices and not all? 2 Answers

Create background service from Android Plugin 0 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