对不起,再次问这个问题,但我尝试了几个解决方案在stackoverflow和其他android组,但他们都没有为我工作。AlertBox调用意图没有点击正面按钮
在活动onBackpressed中,我想显示一个警告框,要求用户“退出应用程序?”如果用户点击是,我想要启动我的应用程序的启动器(主页)活动,否则请单击否按钮保留在同一页面上。 问题是显示警告框后,我自动重定向到发射器(家庭)活动之前,我自动按YES键
plz帮助
CODE:
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
Log.i(TAG, "BACK PRESSED");
AlertDialog.Builder renameDialog = new AlertDialog.Builder(MainMenu.this);
renameDialog.setTitle("Warning");
renameDialog.setMessage("Do you want to logout?");
renameDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
launchIntent();
}
});
renameDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
arg0.cancel();
}
});
renameDialog.show();
}
private void launchIntent() {
Log.i("positive button","pressed");
Intent i=new Intent(MainMenu.this,LoginActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Log.e("from main menu","calling login");
startActivity(i);
}
你究竟想要做什么 – Ishu 2012-04-02 02:57:40