从Unity调用和停止Android活动

时间:2019-02-01 10:39:46

标签: android unity3d

如何从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(),但是没有任何效果。

0 个答案:

没有答案