對不起,再次問這個問題,但我嘗試了幾個解決方案在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