I’ve come across something unusual in my unity project, I’m using AndroidJavaClass to access some static methods in an Android plugin i made.
My wrapper class looks like this:
private AndroidJavaClass AJCplugin;
void Start() {
AJCplugin = new AndroidJavaClass("com.auth.cdbr3d.bitworks.BitmapManipulator");
}
public string Test() {
if ( AJCplugin != null ) {
return AJCpluign.CallStatic<string>("TestMethod", "WORKING");
}
else {
return "AJC is null";
}
}
When the class is configured this way, AJCplugin is always null.
However, if i move things around so its like this:
private AndroidJavaClass AJCplugin;
bool bl = true;
public string TestInterface() {
if ( bl ) {
AJCplugin = new AndroidJavaClass( "com.auth.cdbr3d.bitworks.BitmapManipulator" );
bl = false;
}
if ( AJCplugin != null ) {
return AJCplugin.CallStatic<string>("TestMethod", "WORKING");
}
else {
return "AJC is null";
}
}
The AJCplugin is never null, even though I’m only assigning it once in both configurations, it seems it never gets assigned if it’s initialized from Start()
or Awake()
It isn’t the end of the world and the application can likely continue to function as normal, but I’m mostly curious as to why this is behaving this way, and if it is normal behavior.