Just have the AsyncTask's 'doInBackground' method return an object
that contains the result of your background computation (including any
possible error).
myAsyncTask = new AsyncTask<MyParams,Progress,MyResult>() {
@Override
protected MyResult doInBackground (MyParams... params) {
MyResult result = new MyResult();
try {
result.answer = doSomethingThatTakesALongTime(params);
}
catch (Exception e) {
result.error = e;
}
return result;
}
@Override
protected void onPostExecute (MyResult result) {
if (result.error != null} {
handleError(result.error);
}
else {
handleOKResult(result);
}
}
};
On Jul 19, 10:29 am, likon <[email protected]> wrote:
> Hi!
>
> AsyncTask turned to be a good solution for dealing with GUI and I
> tried to use it instead of own implementation. The problem I met is
> that it isn't designed for an error handling.
> Imagine network activity - there easily can be a connection or timeout
> error and previously I tried to report user not only result but
> consequence also.
> I looked on the Shelves application - it isn't supposed to say
> anything except "importing finished with error" or something like this
> and this statement is based on the null in the return statement.
>
> I see couple of ways to implement this - the easiest is to use kind of
> holder for storing "business" result or an error. Another - may be to
> extend AsyncTask to handle exceptions and to add method like onFailure
> (Object o, Throwable t).
>
> Could you please comment these approaches. Is it right solution from
> your point of view?
>
> Best regards,
> Dmitriy
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---