package com.esafirm.rximagepicker;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.esafirm.imagepicker.features.ImagePicker;
import com.esafirm.imagepicker.model.Image;

import java.util.List;

import rx.Observable;
import rx.subjects.PublishSubject;


public class RxImagePicker {

    @SuppressLint("StaticFieldLeak")
    private static RxImagePicker INSTANCE;

    public static RxImagePicker getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new RxImagePicker();
        }
        return INSTANCE;
    }

    /* --------------------------------------------------- */
    /* > RxImagePicker */
    /* --------------------------------------------------- */

    private PublishSubject<List<Image>> subject;

    private RxImagePicker() {
        this.subject = PublishSubject.create();
    }

    public Observable<List<Image>> start(Context context, ImagePicker imagePicker) {
        startImagePicker(context, imagePicker);
        return subject;
    }

    private void startImagePicker(Context context, ImagePicker imagePicker) {
        Bundle bundle = imagePicker.getIntent(context).getExtras();
        Intent intent = ShadowActivity.getStartIntent(context, bundle)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(intent);
    }

    void onHandleResult(List<Image> images) {
        subject.onNext(images);
        subject.onCompleted();
    }
}

@@ -338,16 +338,54 @@
 ubject;%0A
+import rx.subjects.SerializedSubject;%0A
 %0A%0Apublic
@@ -822,23 +822,39 @@
 ate 
-PublishSubject%3C
+SerializedSubject%3CList%3CImage%3E, 
 List
@@ -925,16 +925,40 @@
 bject = 
+new SerializedSubject%3C%3E(
 PublishS
@@ -968,16 +968,29 @@
 ect.
+%3CList%3CImage%3E%3E
 create()
 ;%0A  
@@ -985,16 +985,17 @@
 create()
+)
 ;%0A    %7D%0A
@@ -1621,39 +1621,8 @@
 s);%0A
-        subject.onCompleted();%0A
     

Make Subject Serializeable