Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * An asynchronous task used fetch the current league's free agents.
- * Returns a FantasyLeague object.
- */
- public class GetFreeAgentsTask extends AsyncTask<Void, Void, FantasyLeague> {
- private List<Exception> exceptions = new ArrayList<Exception>();
- @Override
- protected FantasyLeague doInBackground(Void... params) {
- try {
- return mLeague.refreshFreeAgents(InDraftActivity.this.getApplicationContext());
- } catch (JSONException e) {
- exceptions.add(e);
- return null;
- } catch (ServerErrorException e) {
- exceptions.add(e);
- return null;
- }
- }
- @Override
- protected void onPostExecute(FantasyLeague league) {
- super.onPostExecute(league);
- // If there are any exceptions, display them via toast.
- for (Exception e : exceptions) {
- if (getApplicationContext() != null) {
- ErrorHelper.showErrorToast(getApplicationContext(), e.getMessage());
- }
- }
- // Handle a failed request with no exceptions.
- if (league == null && exceptions.isEmpty()) {
- if (getApplicationContext() != null) {
- ErrorHelper.showErrorToast(getApplicationContext(), "Failed to retrieve free agents.");
- }
- }
- // Handle the normal result.
- onGetFreeAgentsResult(league);
- }
- }
Add Comment
Please, Sign In to add comment