onBackPressed()第一次没有工作

时间:2013-03-06 07:46:32

标签: android android-tabhost android-tablelayout android-tabs

当我从tabview打开一个新活动但是在那个活动上onBackPressed()第一次没有工作enter image description here

更多代码细节添加frist活动意味着第一个iamge和第二个活动意味着第二个图像我试图在第二个活动的后退按钮上执行其他操作 第一项活动

    @Override
public void onBackPressed() {
    //super.onBackPressed();

    //finish();
    //Toast.makeText( getApplicationContext(),"Back pressed",Toast.LENGTH_SHORT).show();


    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this.getParent()); 

    alertDialog.setTitle("Confirm Exit ..."); 
    alertDialog.setMessage("Are you sure to exit ?"); 
    alertDialog.setIcon(R.drawable.tick); 

    alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog,int which) {
            AppPreferenceStatus.setLoggedOutStatus(CurContext, true);
            finish();
            //System.runFinalizersOnExit(true);
            //System.exit(0);
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } 
    }); 

    alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog, int which) { 
        dialog.cancel(); 
        } 
    }); 

    alertDialog.show();

}

第二项活动

@Override
public void onBackPressed() {
    super.onBackPressed();
}

0 个答案:

没有答案
相关问题