public static void RestartOrKillApp()
{
if (Application.isEditor) return;
if (Application.platform == RuntimePlatform.Android)
{
using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
const int kIntent_FLAG_ACTIVITY_CLEAR_TASK = 0x00008000;
const int kIntent_FLAG_ACTIVITY_NEW_TASK = 0x10000000;
var currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
var pm = currentActivity.Call<AndroidJavaObject>("getPackageManager");
var intent = pm.Call<AndroidJavaObject>("getLaunchIntentForPackage", Application.identifier);
intent.Call<AndroidJavaObject>("setFlags", kIntent_FLAG_ACTIVITY_NEW_TASK | kIntent_FLAG_ACTIVITY_CLEAR_TASK);
currentActivity.Call("startActivity", intent);
currentActivity.Call("finish");
var process = new AndroidJavaClass("android.os.Process");
int pid = process.CallStatic<int>("myPid");
process.CallStatic("killProcess", pid);
}
}
else if (Application.platform == RuntimePlatform.IPhonePlayer)
{
//测试只有下面俩种类型好用,FatalError几率卡界面
UnityEngine.Diagnostics.Utils.ForceCrash(UnityEngine.Diagnostics.ForcedCrashCategory.FatalError);
//UnityEngine.Diagnostics.Utils.ForceCrash(UnityEngine.Diagnostics.ForcedCrashCategory.PureVirtualFunction);
}
else
{
Application.Quit();
}
}