我正在制作一款游戏,当你触摸图像的任何位置时,弹出一个1000毫秒的游戏。但这就是问题如果我关闭活动就会崩溃,所以我添加了一个时间处理程序来关闭活动。但那产生了另一个问题。似乎正在调用新活动,但是te处理程序不会关闭活动。
我附加问题出现的lvl1的活动。 (我使用不同颜色的背景不可见图像来设置可触摸区域。例如,背景颜色为白色,返回弹出窗口。当它为黄色时,它会调用另一个活动,依此类推。(颜色不对似乎在摩托罗拉Dunno上工作的原因。))
这是弹出窗口的处理程序
else if (ct.closeMatch (Color.WHITE, touchColor, tolerance)) // con esto evito poing & click muy seguidos
{
Random r = new Random();
int txt= r.nextInt(6-0) + 0;
if(txt==0){ variables.pointtxt = "Nothing interesting"; }
else if (txt==1){ variables.pointtxt = "There´s nothing there"; }
else if (txt==2){ variables.pointtxt = "I can´t do nothing with that"; }
else if (txt==3){ variables.pointtxt = "Wait... nop nothing"; }
else if (txt==4){ variables.pointtxt = "Nothing"; }
else if (txt==5){ variables.pointtxt = "More nothing"; }
LayoutInflater layoutInflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
TextView text = (TextView) popupView.findViewById(R.id.popuptxt);
text.setText(variables.pointtxt);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 250);
new Handler().postDelayed(new Runnable() {
public void run() {
if (popupWindow.isShowing()== true)
popupWindow.dismiss();
}
}, 1100
);
}
handledHere = true;
break;
default:
handledHere = false;
} // end switch
这就是我关闭活动并调用新活动的方式
else if (ct.closeMatch (Color.YELLOW, touchColor, tolerance)) {
Intent game = new Intent(lvl1.this, lvl1_0.class); startActivity(game);
Handler mHandler1 = new Handler();
{
Runnable mLaunchTask3 = null;
mHandler1.postDelayed(mLaunchTask3,1100);
}
//will launch the activity
Runnable mLaunchTask3 = new Runnable() {
public void run() {
lvl1.this.finish();
}
};
}
答案 0 :(得分:0)
使用此代码在关闭活动时删除处理程序:
mHandler1.removeCallbacksAndMessages(null);
因为当你启动新的处理程序时,之前的处理程序将不会删除,它将继续在后台运行