Monday, June 6, 2011

Unity3D 3.3 integrated with Android 3.0 apps (Activity Switch)

Recently when working in a project, I feel painful with the Unity 3.3 integration in Android 3.0.

When I'm trying to go to another activity from UnityPlayerActivity, it will go exiting the whole apps and restart it with Main Activity.

I spent almost a week on it and finally got fix under Ping's help. Thanks Ping.

The problem is based on UnityPlayer class it self, looking into the class jar package, we found this line in onDestory() under UnityPlayer class:

a.quit()

which a is a UnityPlayer instance.


UnityPlayerActivity is extending from UnityPlayer so it surly will exit the app when switching into another activity.

What we did is make our game activity extends from Activity instead of UnityPlayerActivity or UnityPlayer. And using codes inside UnityPlayer to "recreate" a Unity gaming activity, but comment the "a.quit()".

Here's a sample code for the activity, it works fine here now.



However, we are still waiting for a offical fix on 3.4 release from Unity3D.

Thanks Ping again! :D

2 comments:

  1. Thanks, been struggling with this forced quit of the entire application for a while. Although I am worried that this approach does not free all the associated memory allocated with the unity player when switching to a new activity.

    ReplyDelete
  2. Hello,
    I am integrating two plugins in my unity project.Single plugin works well in unity.But if i add two plugins it does not work.Actually I am not able to fire an intent.It gives "Unable to start Activity" Error.I read your answer but I am not getting it properly.Can you please explain in detail.

    ReplyDelete