title: Download Image via Glide with rxJava
body: <p>I need to download pictures (Bitmaps) via a given url. As I use Glide in my project to display the pictures I thought I could simply use their mechanism to download the pictures as well. I need to use it in a RxJava Environment and my problem is that the callback onResourceReady() is not called and of course the methods subscriber.onNext() and subscriber.onCompleted() are not getting called either. </p>
  
  <p>I get an IllegalStateException (see below). I guess the call to Glide needs to be done on the main thread instead of the io thread where get() will be called. Is there a way to achieve this?</p>
  
  <p>This is what id do:</p>
  
  <pre><code>public Observable&lt;Bitmap&gt; get(final String url) {
      return Observable.create(new Observable.OnSubscribe&lt;Bitmap&gt;() {
          @Override
          public void call(final Subscriber&lt;? super Bitmap&gt; subscriber) {
              Glide
                      .with(context)
                      .asBitmap()
                      .load(url)
                      .into(new SimpleTarget&lt;Bitmap&gt;() {
                          @Override
                          public void onResourceReady(Bitmap resource, Transition&lt;? super Bitmap&gt; transition) {
                              // the method onResourceReady is not getting called
                              subscriber.onNext(resource);
                              subscriber.onCompleted();
                          }
                      });
          }
      });
  }
  </code></pre>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: You must call this method on the main thread
    09-13 14:24:58.173 25581 25581 W System.err:    at com.bumptech.glide.util.Util.assertMainThread(Util.java:132)
    09-13 14:24:58.173 25581 25581 W System.err:    at com.bumptech.glide.RequestBuilder.into(RequestBuilder.java:350)
    09-13 14:24:58.176 25581 25581 W System.err:    at de.dumont.bob10.data.repository.image.ImageCloud$2.call(ImageCloud.java:53)
    09-13 14:24:58.178 25581 25581 W System.err:    at de.dumont.bob10.data.repository.image.ImageCloud$2.call(ImageCloud.java:44)
    09-13 14:24:58.179 25581 25581 W System.err:    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50)
    09-13 14:24:58.180 25581 25581 W System.err:    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-13 14:24:58.181 25581 25581 W System.err:    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50)
    09-13 14:24:58.182 25581 25581 W System.err:    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-13 14:24:58.183 25581 25581 W System.err:    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50)
    09-13 14:24:58.183 25581 25581 W System.err:    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-13 14:24:58.184 25581 25581 W System.err:    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50)
    09-13 14:24:58.185 25581 25581 W System.err:    at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
    09-13 14:24:58.186 25581 25581 W System.err:    at rx.Observable.unsafeSubscribe(Observable.java:8666)
    09-13 14:24:58.187 25581 25581 W System.err:    at rx.internal.operators.OperatorSwitchIfEmpty$ParentSubscriber.subscribeToAlternate(OperatorSwitchIfEmpty.java:79)
    09-13 14:24:58.188 25581 25581 W System.err:    at rx.internal.operators.OperatorSwitchIfEmpty$ParentSubscriber.onCompleted(OperatorSwitchIfEmpty.java:72)
    09-13 14:24:58.188 25581 25581 W System.err:    at rx.internal.operators.OperatorSwitchIfEmpty$AlternateSubscriber.onCompleted(OperatorSwitchIfEmpty.java:112)
    09-13 14:24:58.189 25581 25581 W System.err:    at rx.internal.operators.OperatorMerge$MergeSubscriber.emitLoop(OperatorMerge.java:650)
    09-13 14:24:58.190 25581 25581 W System.err:    at rx.internal.operators.OperatorMerge$MergeSubscriber.emit(OperatorMerge.java:562)
    09-13 14:24:58.191 25581 25581 W System.err:    at rx.internal.operators.OperatorMerge$MergeSubscriber.onCompleted(OperatorMerge.java:283)
    09-13 14:24:58.192 25581 25581 W System.err:    at rx.internal.operators.OperatorMap$MapSubscriber.onCompleted(OperatorMap.java:94)</p>
  </blockquote>