Android: stopping the thread while using Alert Dialog
I have a program which first detects whether SD-card is present or not, if sd-card is not present, an alert dialog is presented which asks the user to retry or to exit. In short, sd-card is a must. However, in the case where there is no sd-card, the application continues working on the thread or the t开发者_运维问答hread continues even after going the alert dialog part of my application. in short, what I want is that my application should wait for the alertdialog and get the input from the user.
Can anyone help me here.. thanks
I dont completely understand your problem, I think following code will help you a little bit. It waits till OK clicked
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Please try again.").setPositiveButton("OK", dialogClickListener).show();
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
//OK button clicked, Add your code here
break;
}
}
};
Edited: If you call alertBox from thread it will not work. You should call alertDialog from a UI threadrunOnUiThread(new Runnable() {
@Override
public void run() {
}
});
精彩评论