android: what is the onCreate equivalent in unity script?

1.5k views Asked by At

I have a unity app that should run on android. I have some native code (inside a plugin) that I need to call in order to process deep-link activation of the app, and I need to call it from my unity script when the app gets reopened by that deep link. Where is the appropriate place to make that call?

Note OnApplicationPause is not a good option, since it mimics onResume, and you MUST NOT process deep links inside onResume on Android because it will cause them to get re-processed over and over every time the app is reopened after the initial click on the deep link.

So basically, I am looking for a lifecycle-equivalent to onCreate, but in unity script (I do not have legal permissions to replace the native unity activity in this case and simply override its onCreate method).

1

There are 1 answers

0
apollosoftware.org On

onCreate() is run basically on the initialization of any activity. It's kind of hard to think about it in terms of Unity3D. When you call a level the Start() and Awake() are called, the latter first. You could potentially UnitySendMessage() from your native plugin on the java Android side. I believe the syntax looks like:

UnityPlayer.UnitySendMessage("GameObjectName1", "MethodName1", "Message to send");

And inside your GameObjectName1 construct MethodName1 method with string params passed:

function void MethodName1 (message:String) {}

Not sure if this will suffice for your needs. I've done comparable with iOS, i'm sure there should be an Android equivalent with Unity3D.