As all we know android dialogs can be only created and show under main UI thread.
The problem is that i have a progress bar and a lot of work being done in a thread and in some part of the progress i must display a dialog and the user must select an option to get the work continuing.
So.. i need to display a dialog in a thread (blocking the thread until the user has selected an option).
I tryed it with this code
public void showDialog(Activity activity) {
Looper.prepare();
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
// set title
alertDialogBuilder.setTitle("");
// set dialog message
alertDialogBuilder
.setMessage(R.string.STREAM_NOT_WIFI)
.setCancelable(false)
.setPositiveButton(R.string.STREAM_NOT_WIFI_YES, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
preload=true;
}
})
.setNegativeButton(R.string.CANCEL, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
preload=false;
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
but i got this message and the dialog is not being showed:
"attempting to initialize hardware acceleration outside of the main thread, aborting"