如何从activity
调用和停止Android unity
统一代码
AndroidJavaObject activityObj= new AndroidJavaObject("com.example.mylibrary2.NewActivityinAndroid");
AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
activityObj.Call("Call", currentActivity);
if(condition meets)
{
activityObj.Call("StopActivity");
}
Android代码
public void Call(Activity activity)
{
Intent myIntent = new Intent(activity,NewActivityinAndroid.class);
activity.startActivity(myIntent);
}
public void StopActivity()
{
// Stopactivity() will be called from unity
// this call should only stop android activity not unity
}
我尝试了activity.finish()
,NewActivityinAndroid.super.finish()
,但是没有任何效果。