我决定将所有对话框放在 Notify 类中。
但是,当我尝试调用对话框时,应用程序崩溃
这是通知类:
public class Notify extends Activity
{
public void errorHandler(String title, Exception e)
{
eH(title, e);
}
public void messageBox(String title, String details)
{
alertDialog(title, details);
}
//***************************************************************
//display error dialog.
//****************************************************************
private void eH(String method, Exception e)
{
Log.e("FIRSTDROID EXCEPTION", method + " : " + e.getMessage());
e.printStackTrace();
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(method);
alertDialog.setMessage(e.getMessage());
alertDialog.setIcon(R.drawable.quiticon);
alertDialog.setCanceledOnTouchOutside(true);
alertDialog.show();
}
//*************************************************************
//generic dialog for messages to the user
//*************************************************************
private void alertDialog(String title, String message)
{
Log.i("Message", message);
AlertDialog.Builder messageBox;
messageBox = new AlertDialog.Builder(null);
messageBox.setTitle(title);
messageBox.setMessage(message);
messageBox.setIcon(R.drawable.infoicon);
messageBox.setNeutralButton("OK", null);
messageBox.setCancelable(false);
messageBox.show();
}
我创建了一个新的 Notify 实例,并调用 messageBox,如下所示:
Notify notify = new Notify();
notify.messageBox("Test Title", "Test Message");