Skip to content

Commit

Permalink
Kill server process if Service.onDestroy is invoked. (cocos#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar authored May 25, 2023
1 parent 9081129 commit debcaba
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;

import com.cocos.aidl.ICocosBinderFactory;
Expand Down Expand Up @@ -68,6 +67,7 @@ public abstract class CocosRemoteRenderServiceBase extends Service {
private int mDefaultRenderTargetHeight = DEFAULT_RENDER_TARGET_HEIGHT;

private boolean mIsClientOffscreenMode = false;
private boolean mIsKillProcessOnDestroy = true;

private class CocosBinderFactory extends ICocosBinderFactory.Stub {
@Override
Expand Down Expand Up @@ -242,6 +242,14 @@ private static boolean isReadExternalStorageAllowed(Context context) {
return allow;
}

/**
* 设置是否在 onDestroy 的时候杀死进程
* @param killProcessOnDestroy 是否在 onDestroy 的时候杀死进程,默认值为 true
*/
public void setKillProcessOnDestroy(boolean killProcessOnDestroy) {
mIsKillProcessOnDestroy = killProcessOnDestroy;
}

@Override
public void onCreate() {
if (BuildConfig.DEBUG) {
Expand Down Expand Up @@ -321,6 +329,10 @@ public void onDestroy() {
JsbBridge.setCallback(null);
mIsCreated = false;
super.onDestroy();

if (!BuildConfig.DEBUG && mIsKillProcessOnDestroy) {
android.os.Process.killProcess(android.os.Process.myPid());
}
}

@Override
Expand Down

0 comments on commit debcaba

Please sign in to comment.