Skip to content

Commit

Permalink
QuestionFragment.showNextQuestion(): Pass a copy of the Classificatio…
Browse files Browse the repository at this point in the history
…nInProgress.

To the AsyncTask, to further avoid concurrent access.
  • Loading branch information
murraycu committed Jan 17, 2015
1 parent 8ac1c56 commit 60bcad3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/src/main/java/com/murrayc/galaxyzoo/app/QuestionFragment.java
Expand Up @@ -556,7 +556,10 @@ private void showNextQuestion(final String questionId, final String answerId) {
//Set the questionID to null to prevent us from starting to save this again
//if the user presses the "Done" button again while we are waiting for our AsyncTask.
//(see our check for a null questionId at the start of this method.)
final SaveClassificationTask task = new SaveClassificationTask(this, mClassificationInProgress);
//We give a _copy_ of the ClassificationInProgress to the AsyncTask,
//to be really sure of avoiding concurrent access to it.
final SaveClassificationTask task = new SaveClassificationTask(this,
new ClassificationInProgress(mClassificationInProgress));
task.execute();
return;
}
Expand Down Expand Up @@ -617,7 +620,7 @@ private static class SaveClassificationTask extends AsyncTask<Void, Void, Void>

SaveClassificationTask(final QuestionFragment fragment, final ClassificationInProgress classificationInProgress) {
this.fragmentReference = new WeakReference<>(fragment);
this.classificationInProgress = classificationInProgress;
this.classificationInProgress = classificationInProgress; //The caller gives us a copy.
}

@Override
Expand Down Expand Up @@ -893,6 +896,11 @@ public ClassificationInProgress() {
answers = new ArrayList<>();
}

public ClassificationInProgress(final ClassificationInProgress in) {
this.answers = in.getAnswers(); //getAnswers() returns a copy.
favorite = in.favorite;
}

public ClassificationInProgress(final Parcel in) {
this.answers = in.createTypedArrayList(QuestionAnswer.CREATOR);

Expand Down

0 comments on commit 60bcad3

Please sign in to comment.