- Home /
Unity3D 5.1 Android Plugin running a service
I just started with a Plugins in unity but i have been some time with Android so i the example to run the share intent system was pretty simple to execute.
My goal is to listen to voice commands, something I had setup already for other Native android app i have developed. This code is a service so the Plugin was created like this: 1 activity that extends UnityPlayerActivity with onCreate and 2 public methods, 1 is a simple share system that works every time and the other is one that calls Android Service, i am using this code:
> public void ListenMe(){
> startService(new Intent(getApplicationContext(),
> VoiceRecognition.class));
> Log.d(TAG,"ListenMe Service started");
> }
The service starts correctly but only until i open Tasklist in Android and kill the Unity App. in that moment i get the Android sound of ready to speak, why is this? why cant the service run why the app is running?
When i look at logcat i can see all the logs i setup and detects words and everything so it works but can run it at the same time as the unity app. Could you please help me out?
LOL, just found out my own solution. In android native code the service did not need to be stopped in order to start a new recognition but in Unity you need to stop the service before using it again or it will run for ever, the OnCreate section was initializing all variables, so they were not been initialized as the service was running for ever, after changing that, now it works as expected.
:)