Skip to content

Commit

Permalink
doInBackground handlers: Check for isCancelled().
Browse files Browse the repository at this point in the history
Just because it is generally good practice:
https://developer.android.com/reference/android/os/AsyncTask.html
However, in this particular code there is no place where we can
periodically check this while doing work.
  • Loading branch information
murraycu committed Mar 16, 2017
1 parent 793d942 commit ab6e3c8
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ protected Boolean doInBackground(final Void... params) {
return Boolean.FALSE;
}

if (isCancelled()) {
return Boolean.FALSE;
}

return LoginUtils.getLoggedIn(context);
}

Expand Down Expand Up @@ -205,6 +209,10 @@ protected Void doInBackground(final Void... params) {
return null;
}

if (isCancelled()) {
return null;
}

final AccountManager mgr = AccountManager.get(context);

//Note this needs the GET_ACCOUNTS permission on
Expand All @@ -216,12 +224,15 @@ protected Void doInBackground(final Void... params) {
return null;
}

if (isCancelled()) {
return null;
}

final Account account = accts[0];

final Bundle extras = new Bundle();
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);


//Ask the framework to run our SyncAdapter.
ContentResolver.requestSync(account, Item.AUTHORITY, extras);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ protected Void doInBackground(final Void... params) {
return null;
}

if (isCancelled()) {
return null;
}

final String accountName = loginResult.getName();

final AccountManager accountManager = AccountManager.get(context);
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/murrayc/galaxyzoo/app/LoginUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ protected LoginDetails doInBackground(final Void... params) {
return null;
}

if (isCancelled()) {
return null;
}

LoginDetails result = null;

try {
Expand Down Expand Up @@ -517,6 +521,10 @@ protected Void doInBackground(final Void... params) {
return null;
}

if (isCancelled()) {
return null;
}

final LoginUtils.LoginDetails loginDetails = LoginUtils.getAccountLoginDetails(context);
if(!LoginUtils.getLoggedIn(loginDetails)) {
return null;
Expand All @@ -527,6 +535,10 @@ protected Void doInBackground(final Void... params) {
return null;
}

if (isCancelled()) {
return null;
}

LoginUtils.removeAccount(context, accountName);

LoginUtils.addAnonymousAccount(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ protected Void doInBackground(final Void... params) {
return null;
}

if (isCancelled()) {
return null;
}

fragment.saveClassificationSync(classificationInProgress);

return null;
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/murrayc/galaxyzoo/app/Singleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ protected Void doInBackground(final Context... params) {
return null;
}

if (isCancelled()) {
return null;
}

final Context context = params[0];
try {
Singleton.ourInstance = new Singleton(context);
Expand Down

0 comments on commit ab6e3c8

Please sign in to comment.