我正在制作一个游戏,当您触摸图像的任何位置时,会弹出 1000 毫秒的弹出窗口。但这就是问题如果我关闭活动它会崩溃,所以我添加了一个时间处理程序来关闭活动。但这又产生了另一个问题。似乎正在调用新活动,但处理程序并未关闭该活动。
我附上了出现问题的 lvl1 的活动。(我使用不同颜色的背景不可见图像来设置可触摸区域。例如,背景颜色为白色的地方,它返回弹出窗口。当它是黄色时,它调用另一个活动等等。(颜色的东西没有'似乎不适用于摩托罗拉不知道为什么。))
这是弹出窗口的处理程序
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();
}
};
}