I'm working on an application which loads some data from the net in a
thread.
However when something goes wrong (no internet connection or sth) I'dd
like to create a dialog to show an error message to the user.
However my code works fine not using threads but creating a dialog
from my thread makes my application crashing.
In my activity I have overwritten the onCreateDialog method and looks
like this:
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch (id) {
case EPISODE_LOADING_DIALOG:
ProgressDialog progressDialog = new
ProgressDialog(this);
progressDialog.setMessage(this.getString
(R.string.progressLoadingTitle));
//progressDialog.setTitle(R.string.progressLoadingTitle);
dialog = progressDialog;
break;
case EXCEPTION_DIALOG:
if (exceptionMessageResId == null) {
exceptionMessageResId =
R.string.defaultExceptionMessage;
}
AlertDialog.Builder builder = new
AlertDialog.Builder(this);
builder.setTitle(R.string.exceptionDialogTitle)
.setMessage(exceptionMessageResId)
.setCancelable(false)
.setPositiveButton(R.string.dialogOK, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface
dialog, int id) {
dialog.cancel();
}
});
exceptionMessageResId = null;
default:
dialog = super.onCreateDialog(id);
}
return dialog;
}
The method which is calling a method and catching an exception (within
a thread):
private void getEpisodes() {
try {
episodes = myEpisodesService.retrieveEpisodes(user);
} catch (InternetConnectivityException e) {
String message = "Could not connect to host";
Log.e(LOG_TAG, message, e);
exceptionMessageResId =
R.string.internetConnectionFailureReload;
showDialog(EXCEPTION_DIALOG);
}
runOnUiThread(returnEpisodes);
}
So does anyone of you guys knows what I am doing wrong here? Can't you
create a dialog from within a thread?
If so, what's the best way of handling my exceptions here?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en