- Home /
Communication between unityplayer and activities
Hi guys, I was wondering, maybe someone had the same problem. I'm using unity into a java project and I have some troubles for sending messages to Unity. Basically in the first activity where I create the unityplayer there is not any problems, I can send messages into regular methods or listeners. But in the second activity, I can only call it in onCreate, onResume, onPause Any idea?
Thanks
Here is the code
First Activity:
private void init() { m_UnityPlayer = UnityConnector.getInstance(this); int glesMode = m_UnityPlayer.getSettings().getInt("gles_mode", 1); boolean trueColor8888 = false; m_UnityPlayer.init(glesMode, trueColor8888); layoutView = (FrameLayout) findViewById(R.id.mapView);
LayoutParams lp = new LayoutParams (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); layoutView.addView(m_UnityPlayer.getView(), 0, lp); //here it works m_UnityPlayer.sendStringToUnity(msg); }
new OnClickListener() {
@Override
public void onClick(View v) {
//here it works
m_UnityPlayer.sendStringToUnity("let's party");
}
});
UnityConnector:
public static UnityConnector getInstance(ContextWrapper context) { if (ptr == null) ptr = new UnityConnector(context); return ptr; }
private UnityConnector(ContextWrapper context) { super(context); this.context = context; }
Second Activity: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); m_UnityPlayer = UnityConnector.getInstance(this); //here it works m_UnityPlayer.sendStringToUnity("Hello"); }
new OnClickListener() {
@Override
public void onClick(View v) {
//here it works when I'm back to the fist activity
m_UnityPlayer.sendStringToUnity("I'm here");
}
});
Your answer
Follow this Question
Related Questions
Finding the version of unity player used 2 Answers
How to pause game when receiving phone call on Android 6? 2 Answers
My Unity Android app is preventing the lock screen from displaying properly 2 Answers
Android Pause conflicting with action 1 Answer
Old camera view flickers for a couple of seconds when camera is changed 0 Answers