Last active
August 29, 2015 14:03
-
-
Save showsky/5c258d8cf66e8e0f15ff to your computer and use it in GitHub Desktop.
AsyncTask handling excpetion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AsyncResult<T> { | |
| public T result; | |
| public Excpetion excpetion; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ----- | |
| @Override | |
| protected final AsyncResult<T> doInBackground(Void... params) { | |
| Result<T> result = new Result<T>(); | |
| try { | |
| result.result = xxxxxx; | |
| } catch (Exception exc) { | |
| result.exc = exc; | |
| } | |
| return result; | |
| } | |
| @Override | |
| protected final void onPostExecute(AsyncResult<R> result) { | |
| if (result.excpetion != null) { | |
| // ... alert the user ... | |
| } else { | |
| // ... success, continue as normal ... | |
| } | |
| } | |
| ----- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment