Commit f3a145f3 authored by kenan's avatar kenan

kill game

parent 17fddcba
......@@ -26,6 +26,14 @@
android:name="android.app.lib_name"
android:value="YGOMobile"/>
</activity>
<receiver
android:name="cn.garymb.ygomobile.AutoQuitReceiver"
android:exported="false">
<intent-filter>
<action android:name="ygocore.action.game_start" />
<action android:name="ygocore.action.game_end" />
</intent-filter>
</receiver>
</application>
</manifest>
package cn.garymb.ygomobile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Process;
import android.util.Log;
import cn.garymb.ygomobile.core.YGOCore;
/***
* 解决重启游戏卡图变黑
*/
public class AutoQuitReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (YGOCore.ACTION_END.equals(intent.getAction())) {
int pid = intent.getIntExtra(YGOCore.EXTRA_PID, -1);
if (pid != 0) {
try {
Log.e("ygomobile", "stop game pid=" + pid);
Process.killProcess(pid);
} catch (Throwable e) {
e.printStackTrace();
}
}
} else if (YGOCore.ACTION_START.equals(intent.getAction())) {
}
}
}
......@@ -171,6 +171,7 @@ public class YGOMobileActivity extends NativeActivity implements
}
mHost.initWindbot(mGameConfig.getNativeInitOptions(), mGameConfig);
mHost.onAfterCreate(this);
sendBroadcast(new Intent(YGOCore.ACTION_START).putExtra(YGOCore.EXTRA_PID, Process.myPid()).setPackage(getPackageName()));
}
@SuppressLint("WakelockTimeout")
......@@ -223,6 +224,7 @@ public class YGOMobileActivity extends NativeActivity implements
public void finish() {
mCore.release();
mHost.onGameExit(this);
sendBroadcast(new Intent(YGOCore.ACTION_END).putExtra(YGOCore.EXTRA_PID, Process.myPid()).setPackage(getPackageName()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
finishAndRemoveTask();
} else {
......
......@@ -18,6 +18,10 @@ import cn.garymb.ygomobile.YGOMobileActivity;
import cn.garymb.ygomobile.interfaces.GameConfig;
public class YGOCore {
public static final String ACTION_START = "ygocore.action.game_start";
public static final String ACTION_END = "ygocore.action.game_end";
public static final String EXTRA_PID = "pid";
public static final float GAME_WIDTH = 1024.0f;
public static final float GAME_HEIGHT = 640.0f;
private static final String TAG = "ygomobile";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment