Commit 527b0d45 authored by 247321453's avatar 247321453

优化清理任务

parent 78406e4b
......@@ -46,7 +46,7 @@ void Game::stopBGM() {
}
void Game::playBGM() {
ALOGV("play bgm");
// ALOGV("play bgm dInfo.isStarted=%d, is_building=%d", dInfo.isStarted, is_building);
gMutex.lock();
if(dInfo.isStarted) {
if(dInfo.isFinished && showcardcode == 1)
......@@ -1348,7 +1348,6 @@ void Game::MainLoop() {
}
#endif
while(device->run()) {
ALOGV("game draw frame");
linePatternD3D = (linePatternD3D + 1) % 30;
linePatternGL = (linePatternGL << 1) | (linePatternGL >> 15);
atkframe += 0.1f;
......
......@@ -23,13 +23,6 @@
android:name="android.app.lib_name"
android:value="YGOMobile"/>
</activity>
<receiver android:name="cn.garymb.ygomobile.GameReceiver"
android:process=":gamehelper" >
<intent-filter>
<action android:name="cn.garymb.ygomobile.game.start"/>
<action android:name="cn.garymb.ygomobile.game.stop"/>
</intent-filter>
</receiver>
</application>
</manifest>
package cn.garymb.ygomobile;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_START;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_STOP;
public class GameReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION_START.equals(action)) {
//
IrrlichtBridge.gPid = intent.getIntExtra(IrrlichtBridge.EXTRA_PID, 0);
} else if (ACTION_STOP.equals(action)) {
int pid = intent.getIntExtra(IrrlichtBridge.EXTRA_PID, 0);
if (pid == 0 && IrrlichtBridge.gPid != 0) {
pid = IrrlichtBridge.gPid;
}
if (pid == 0) {
pid = android.os.Process.myPid();
}
try {
android.os.Process.killProcess(pid);
} catch (Exception e) {
//ignore
}
}
}
}
......@@ -43,8 +43,6 @@ import cn.garymb.ygomobile.widget.overlay.OverlayOvalView;
import cn.garymb.ygomobile.widget.overlay.OverlayView;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_SHARE_FILE;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_START;
import static cn.garymb.ygomobile.core.IrrlichtBridge.ACTION_STOP;
/**
* @author mabin
......@@ -132,9 +130,6 @@ public class YGOMobileActivity extends NativeActivity implements
mPM = (PowerManager) getSystemService(Context.POWER_SERVICE);
mNetController = new NetworkController(getApplicationContext());
handleExternalCommand(getIntent());
sendBroadcast(new Intent(ACTION_START)
.putExtra(IrrlichtBridge.EXTRA_PID, android.os.Process.myPid())
.setPackage(getPackageName()));
}
//电池管理
......@@ -195,14 +190,6 @@ public class YGOMobileActivity extends NativeActivity implements
super.onDestroy();
}
@Override
public void finish() {
super.finish();
sendBroadcast(new Intent(ACTION_STOP)
.putExtra(IrrlichtBridge.EXTRA_PID, android.os.Process.myPid())
.setPackage(getPackageName()));
}
private void handleExternalCommand(Intent intent) {
YGOGameOptions options = intent
.getParcelableExtra(YGOGameOptions.YGO_GAME_OPTIONS_BUNDLE_KEY);
......@@ -551,20 +538,31 @@ public class YGOMobileActivity extends NativeActivity implements
return;
}
onGameExiting = true;
Log.e("ygomobile", "game exit");
final Intent intent = new Intent("ygomobile.intent.action.GAME");
Log.e(IrrlichtBridge.TAG, "game exit");
final Intent intent = new Intent(IrrlichtBridge.ACTION_OPEN_GAME_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
intent.putExtra("game_exit_time", System.currentTimeMillis());
// intent.putExtra(IrrlichtBridge.EXTRA_PID, Process.myPid());
// intent.putExtra(IrrlichtBridge.EXTRA_TASK_ID, getTaskId());
// intent.putExtra(IrrlichtBridge.EXTRA_GAME_EXIT_TIME, System.currentTimeMillis());
intent.setPackage(getPackageName());
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
startActivity(intent);
} catch (Throwable ignore) {}
finishAndRemoveTask();
Log.d(IrrlichtBridge.TAG, "open home ok");
} catch (Throwable e) {
Log.w(IrrlichtBridge.TAG, "open home", e);
}
boolean isRoot = isTaskRoot();
Log.d(IrrlichtBridge.TAG, "isRoot=" + isRoot + ",kill:" + Process.myPid());
if(isRoot) {
finishAndRemoveTask();
} else {
finish();
}
Process.killProcess(Process.myPid());
}
});
......
......@@ -26,8 +26,7 @@ import static cn.garymb.ygomobile.utils.ByteUtils.byte2uint;
* @author mabin
*/
public final class IrrlichtBridge {
public static final String ACTION_START = "cn.garymb.ygomobile.game.start";
public static final String ACTION_STOP = "cn.garymb.ygomobile.game.stop";
public static final String ACTION_OPEN_GAME_HOME = "ygomobile.intent.action.GAME";
/**
* @see #EXTRA_SHARE_FILE
* @see #EXTRA_SHARE_TYPE
......@@ -38,6 +37,11 @@ public final class IrrlichtBridge {
public static final String EXTRA_PID = "extras.mypid";
public static final String EXTRA_ARGV = "extras.argv";
public static final String EXTRA_ARGV_TIME_OUT = "extras.argv_timeout";
public static final String EXTRA_GAME_EXIT_TIME = "game_exit_time";
public static final String EXTRA_TASK_ID = "extras.taskid";
public static final String TAG = "ygo-java";
public static int gPid;
static {
try {
......@@ -74,7 +78,6 @@ public final class IrrlichtBridge {
private static native void nativeSetInputFix(long handle, int x, int y);
private static final boolean DEBUG = false;
private static final String TAG = IrrlichtBridge.class.getSimpleName();
public static void setArgs(Intent intent, String[] args) {
intent.putExtra(EXTRA_ARGV, args);
......
......@@ -25,13 +25,6 @@
android:name="android.notch_support"
android:value="true"/>
</activity>
<receiver android:name="cn.garymb.ygomobile.GameReceiver"
android:process=":game" >
<intent-filter>
<action android:name="cn.garymb.ygomobile.game.start"/>
<action android:name="cn.garymb.ygomobile.game.stop"/>
</intent-filter>
</receiver>
</application>
</manifest>
......@@ -124,10 +124,6 @@
android:theme="@style/AppTheme.Game"
tools:replace="android:theme" />
<receiver
android:name="cn.garymb.ygomobile.GameReceiver"
android:enabled="false" />
<activity
android:name="cn.garymb.ygomobile.ui.preference.SettingsActivity"
android:configChanges="orientation|keyboardHidden|navigation|screenSize"
......
......@@ -678,8 +678,4 @@ public class AppsSettings {
// Log.i("kk", "saveTemp:" + array);
mSharedPreferences.putString(Constants.PREF_LAST_ROOM_LIST, array.toString());
}
public boolean isAutoCheckUpdate(){
return true;//mSharedPreferences.getBoolean(Constants.PREF_CHECK_UPDATE, false);
}
}
package cn.garymb.ygomobile.ui.home;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Color;
......@@ -63,7 +62,6 @@ import java.util.List;
import cn.garymb.ygodata.YGOGameOptions;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.YGOMobileActivity;
import cn.garymb.ygomobile.YGOStarter;
import cn.garymb.ygomobile.bean.Deck;
import cn.garymb.ygomobile.bean.ServerInfo;
......@@ -87,7 +85,6 @@ import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.ui.preference.SettingsActivity;
import cn.garymb.ygomobile.ui.widget.Shimmer;
import cn.garymb.ygomobile.ui.widget.ShimmerTextView;
import cn.garymb.ygomobile.utils.ComponentUtils;
import cn.garymb.ygomobile.utils.FileLogUtil;
import cn.garymb.ygomobile.utils.ScreenUtil;
import cn.garymb.ygomobile.utils.YGOUtil;
......@@ -126,7 +123,6 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
AnimationShake();
tv = (ShimmerTextView) findViewById(R.id.shimmer_tv);
toggleAnimation(tv);
QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {
@Override
public void onViewInitFinished(boolean arg0) {
......@@ -144,14 +140,12 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
};
//x5内核初始化接口
QbSdk.initX5Environment(this, cb);
if(AppsSettings.get().isAutoCheckUpdate()) {
if (!"ygomobile.intent.action.GAME".equals(getIntent().getAction())) {
Log.d("kk-test", "start check update");
//check update
Beta.checkUpgrade(false, false);
} else {
Log.d("kk-test", "skip check update");
}
if (!Constants.ACTION_OPEN_GAME.equals(getIntent().getAction())) {
Log.d(Constants.TAG, "start check update");
//check update
Beta.checkUpgrade(false, false);
} else {
Log.d(Constants.TAG, "skip check update");
}
//初始化决斗助手
initDuelAssistant();
......
......@@ -2,7 +2,6 @@ package cn.garymb.ygomobile.ui.home;
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
......@@ -22,15 +21,11 @@ import java.io.IOException;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.Constants;
import cn.garymb.ygomobile.GameUriManager;
import cn.garymb.ygomobile.YGOMobileActivity;
import cn.garymb.ygomobile.YGOStarter;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.activities.PermissionsActivity;
import cn.garymb.ygomobile.ui.activities.WebActivity;
import cn.garymb.ygomobile.ui.plus.DialogPlus;
import cn.garymb.ygomobile.ui.plus.VUiKit;
import cn.garymb.ygomobile.utils.ComponentUtils;
import cn.garymb.ygomobile.utils.FileUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import cn.garymb.ygomobile.utils.NetUtils;
......@@ -195,10 +190,6 @@ public class MainActivity extends HomeActivity {
protected void onResume() {
super.onResume();
YGOStarter.onResumed(this);
//如果游戏Activity已经不存在了,则
if (!YGOStarter.isGameRunning(getActivity())) {
sendBroadcast(new Intent(IrrlichtBridge.ACTION_STOP).setPackage(getPackageName()));
}
}
@Override
......@@ -318,5 +309,4 @@ public class MainActivity extends HomeActivity {
/* checkResourceDownload((result, isNewVersion) -> {
Toast.makeText(this, R.string.tip_reset_game_res, Toast.LENGTH_SHORT).show();
});*/
}
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