android(back)返回键监听
public boolean dispatchKeyEvent(KeyEvent event) {
目前创新互联已为1000+的企业提供了网站建设、域名、网络空间、网站托管、服务器租用、企业网站设计、射阳网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
// TODO Auto-generated method stub
if(event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_BACK){
showDialog();
return false;
}
return super.dispatchKeyEvent(event);
}
public void showDialog(){
final CheckBox check = new CheckBox(this);
check.setText("退出后仍然接收通知 ?");
new AlertDialog.Builder(this)
.setTitle(R.string.app_name)
.setView(check)
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
if(check.isSelected() == true){
startBackService();
}
System.exit(0);
finish();
}
})
.show();
}
网页标题:android(back)返回键监听
当前地址:http://myzitong.com/article/jhgjop.html