Permalink
Browse files

QuestionFragment.showNextQuestion(): Pass a copy of the Classificatio…

…nInProgress.

To the AsyncTask, to further avoid concurrent access.
  • Loading branch information...
murraycu committed Jan 17, 2015
1 parent 8ac1c56 commit 60bcad361d4d75c8f294d47ba05fbfead942567d
Showing with 10 additions and 2 deletions.
  1. +10 −2 app/src/main/java/com/murrayc/galaxyzoo/app/QuestionFragment.java
@@ -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;
}
@@ -617,7 +620,7 @@ private void restartClassification() {

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
@@ -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);

0 comments on commit 60bcad3

Please sign in to comment.