当用户想要退出时,会弹出一个对话框,确定,游戏将退出。我的代码不会调用另一个类。
private void giveup(){
Context mcontext=this;
final AlertDialog.Builder alert = new AlertDialog.Builder(
mcontext);
alert.setTitle("Are you sure to give up?");
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
click.start();
dialog.cancel();
} });
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
click.start();
dialog.cancel();
try{
Class<?> ourClass = Class.forName("com.ithinkDictionary.Gameover");
Intent ourIntent = new Intent(Playing.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
});
alert.show();
}
}
答案 0 :(得分:3)
你应该使用
Intent ourIntent = new Intent(Playing.this, Gameover.class);
startActivity(ourIntent);
假设Play和Gameover都是活动。