Search Issue Tracker
Fixed in 2021.2.X
Votes
0
Found in
2018.4
2019.4
2019.4.3f1
2020.1
2020.2
2021.1
Issue ID
1277152
Regression
No
There is no way to have 2 instances of AndroidJavaObject with different references
Use cases:
1 AndroidJavaObject needs to be passed to multiple independent bodies of code -- each which have their own independent duration for holding onto the AndroidJavaObject.
One returns an AndroidJavaObject from an AndroidJavaProxy method then AndroidJavaProxy automatically calls Dispose() on that AndroidJavaObject outside the developer's visibility or control while other code may need to continue using that AndroidJavaObject.
Workaround script:
public static AndroidJavaObject NewAndroidJavaObject(AndroidJavaObject androidJavaObject)
{
if (androidJavaObject == null)
{
return null;
}
AndroidJavaClass objectsClass = AndroidUtilities.objectsClass;
if (objectsClass == null)
{
AndroidUtilities.objectsClass = objectsClass = new AndroidJavaClass("java.util.Objects");
}
return objectsClass.CallStatic<AndroidJavaObject>("requireNonNull", androidJavaObject);
}
Notes:
Related forum thread: https://forum.unity.com/threads/androidjavaobject-any-way-to-clone-for-separate-dispose-management.967609/
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Mobile] Developer Console does not appear when an error is thrown
- [HDRP] Game view renders artifacts when Camera's Component "Post Anti-aliasing" is set to "TAA" and Dynamic Resolution's "Forced Screen Percentage" is changed
- A deactivated Prefab's name color becomes white when a GameObject in the scene is deactivated
- The Game view becomes blank when using Frame Debugger with MSAA and Texture binding enabled in Play Mode
- NullReferenceException is thrown when changing the Inspector preview selection
Add comment