我想在出现异常时发出警报,例如在代码中:
try
{
//the code here
}
catch(Exception e)
{
//show an alert dialog here
}
Run Code Online (Sandbox Code Playgroud)
我需要一个示例或代码片段.
这是我的代码初始化AlertDialog; buildexit是AlertDialog.Builder和exitalert是AlertDialog:
buildexit=new AlertDialog.Builder(this);
buildexit.setTitle("Exit?");
buildexit.setIcon(R.drawable.ic_action_warning);
buildexit.setMessage("Do you want to really exit?");
buildexit.setPositiveButton("Yes", this);
buildexit.setNegativeButton("No", this);
exitalert=buildexit.create();
Run Code Online (Sandbox Code Playgroud)
我想Activity.finish()在用户点击"是"按钮时使用方法终止应用程序,如果"否"点击什么都不应该发生,我也实现了android.content.DialogInterface.OnClickListener界面,实现的方法是public void onClick(DialogInterface arg0, int arg1).
提前致谢.