I searched through Stackoverflow, looked at examples in Android Developer and some books, and I just don't get it.
I am trying to show an AlertDialog window that interrupts the program flow. Most of the examples I saw do not have code after the dialog box, and I need my program to stop executing until the AlertDialog button is clicked. It seems that AlertDialog is created from another thread, and I'm not sure how to extract this thread.
Program logic: if the parsing is bad, the program will be forced to close. I want to tell the user to restart the program, and everything will work. (I drop and recreate the tables, and they populate when the program starts)
Here is the code:
if(database populated) { ....code..... if(parseok.contentEquals("Error")) { doForceClose(); } displayDate = "Last: " + parseok;
Here's the AlertDialog method:
private void doForceClose() { String themessage = "Because some of the parameters have changed in the yada yada"; AlertDialog.Builder ad = new AlertDialog.Builder (this); ad.setTitle("Internal Error"); ad.setMessage(themessage); ad.setPositiveButton("Sorry", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); return; } }); ad.create(); ad.show(); }
except for the ad is not displayed, and the program continues to close its power.
Obviously, I am not getting anything. Any ideas?
edit: I'm in a class that extends Activity
source share