I have created a dialog which can be called from anywhere by supplying a title and message as follows:
public void alertbox(String title, String mymessage)
{ new AlertDialog.Builder(this)
.setTitle(title)
.setMessage(mymessage)
.setNeutralButton(android.R.string.cancel,
new DialogInterface.OnClickListener()
{ public void onClick(DialogInterface dialog, int whichButton) {}
})
.show();
}
But I get a lockup when I try to dismiss the dialog from another method:
private void doCheck() {
alertbox("status", getString(R.string.checking_license));
mChecker.checkAccess(mLicenseCheckerCallback);
alertbox.dismiss();
}
It is the alertbox.dismiss(); statement that causes the crash. Any ideas how to properly do this?
It could be as simple as calling
runOnUiThread:if you are on the wrong thread. Although with your additional details, the problem is more simple. To give away the punchline:
and:
Although you probably don’t want to both show and dismiss the dialog in the same method. Do you see how the above code is at least saving a reference to the dialog so that you can dismiss it later?