package com.carrotcreative.cream.tasks;

import android.os.AsyncTask;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;

public class ReadSerializableTask extends AsyncTask<Void, Void, Void> {

    private ReadSerializableCallback mCallback;
    private File mFileToRead;

    public ReadSerializableTask(ReadSerializableCallback callback, File toRead){
        mCallback = callback;
        mFileToRead = toRead;
    }

    @Override
    protected Void doInBackground(Void... params) {

        Exception exception = null;
        Serializable serializableObject = null;
        FileInputStream fis = null;
        ObjectInputStream is = null;

        try {
            fis = new FileInputStream(mFileToRead);
            is = new ObjectInputStream(fis);
            serializableObject = (Serializable) is.readObject();
        } catch(Exception e) {
            exception = e;
        } finally {
            try {
                if (fis != null)   fis.close();
                if (is != null)   is.close();
            } catch (Exception e) { /* Do nothing */ }
        }

        if(serializableObject != null){
            mCallback.success(serializableObject);
        }
        else{
            mCallback.failure(exception);
        }

        return null;
    }

    protected void onPostExecute(Void value)
    {
        super.onPostExecute(value);
        mCallback.always();
    }

    public interface ReadSerializableCallback {
        void success(Serializable object);
        void failure(Exception error);
        void always();
    }

}
@@ -245,20 +245,28 @@
 , Void, 
-Void
+Serializable
 %3E %7B%0A%0A   
@@ -339,16 +339,50 @@
 eToRead;
+%0A    private Exception mException;
 %0A%0A    pu
@@ -551,20 +551,28 @@
 otected 
-Void
+Serializable
  doInBac
@@ -598,47 +598,14 @@
 ams)
- %7B%0A
 %0A    
-    Exception exception = null;
+%7B
 %0A   
@@ -942,17 +942,18 @@
         
-e
+mE
 xception
@@ -1168,11 +1168,15 @@
     
-if(
+return 
 seri
@@ -1193,234 +1193,194 @@
 ject
- != null)%7B
+;
 %0A    
+%7D%0A%0A
     
-    mCallback.success(serializableObject);%0A        %7D%0A        else%7B%0A            mCallback.failure(exception);%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A    protected void onPostExecute(Void value)
+protected void onPostExecute(Serializable obj)%0A    %7B%0A        super.onPostExecute(obj);%0A%0A        if(obj != null)%0A            mCallback.success(obj);%0A        else
 %0A    
-%7B%0A
         
 supe
@@ -1379,36 +1379,40 @@
     
-super.onPostExecute(value
+mCallback.failure(mException
 );%0A
+%0A
     

Read Task calling back on UI thread fixes #1