Using RxJava and Okhttp

前端 未结 5 1894
情书的邮戳
情书的邮戳 2020-12-14 17:15

I want to request to a url using okhttp in another thread (like IO thread) and get Response in the Android main thread, But I don\'t know how to create an

5条回答
  •  甜味超标
    2020-12-14 17:25

    I realise this post is a bit old, but there's a new and more convenient way of doing this now

    Observable.fromCallable {
            client.newCall(Request.Builder().url("your url").build()).execute()
        }
    

    More info: https://artemzin.com/blog/rxjava-defer-execution-of-function-via-fromcallable/

提交回复
热议问题