活动GameActivity
:首次打开应用程序时打开的页面。
活动GameMain
:游戏的游戏活动。
活动GameWin
:转移到下一个GameActivity
(最终将有一个“你赢了!”屏幕,包含统计数据和事物)
这是触发的:
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(context, GameMain.class);
intent.putExtra("level",1);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
});
GameMain
现已加载。角色circle
现在位于屏幕的左侧。
当circle
到达屏幕的右侧时,我的游戏循环中的if语句现在变为true:
if ((circle.x+width/2 > end.startx) && (circle.x-width/2 < end.stopx) && (circle.y+circle.size==end.starty-width/2)) {
layout.removeAllViews();
Intent intent = new Intent(context, GameWin.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("level",level);
finish();
startActivity(intent);
}
GameWin
屏幕执行此操作:
Log.v(TAG,"Goint to level: "+(level+1));
Intent intent = new Intent(context, GameMain.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("level",(level+1));
startActivity(intent);
finish();
有时它会起作用,并且以{2}的级别数据转到GameMain
,比我通过关卡屏幕并直接升级到level2要慢得多。有时它可以工作,并转到GameMain
,级别数据为2,并重复加载页面一遍又一遍。有时,我的手机会重新启动。
如果我有能力完成2级,我会这样做。如果工作,刷新或重新启动手机,3级甚至更慢。
如果我随时点击“主页”,它会转到我的主屏幕,但应用程序会自行打开返回到最后一级的GameMain
(返回步骤6或7)。
我做错了什么?
API等级8,LG P500(2.3.3)
事实证明这不是问题所在。游戏循环仍然在后台运行。
答案 0 :(得分:0)
这里有两件事要尝试:
startActivity(intent)
finish()
编辑您应该开始向函数和回调添加日志记录语句。这将向您显示正在运行的内容,并为您提供有关其运行时间的计时信息。例如:
onCreate(){
Log.i(TAG, "onCreate++");
super.onCreate();
//other code here
Log.i(TAG, "onCreate--");
}
答案 1 :(得分:0)
事实证明,这只是意图的问题;主要问题是我没有停止游戏循环。
当游戏循环停止时,一切正常。