Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
OkHttp3+Retrofit2+...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yoshihisa
February 01, 2018
Technology
4.7k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
OkHttp3+Retrofit2+...
OkHttp3とRetrofit2そしてコルーチンを組み合わせて非同期通信を実現するお話
Yoshihisa
February 01, 2018
More Decks by Yoshihisa
See All by Yoshihisa
Android Architecture Componentsを使ってリファクタリングした話
yoshihisa
0
1.8k
Other Decks in Technology
See All in Technology
ストレスなくAIと付き合いたい!こんなときどうしてる?
namiki64
3
490
事業成長とデータ活用を止めないためのマネジメントへ挑戦
hiracky16
0
390
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
110
[JAWS-UG彩の国埼玉#12]そろそろ準備する?re:Invent2026をやさしく解説 / reinvent2026-sainokuni
sh_fk2
1
340
Claude Code本は、どのように執筆チームで書かれたか
oikon48
1
380
AI導入は済んだ。次は統制を作り替える番だ_AI×開発組織 Summit 2026
techtekt
PRO
0
210
二歩目のフロントエンド・ウェブアクセシビリティ
camiha
2
570
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
1.7k
re:Invent初参加で変わったこと、2回目にやってみたいこと(JAWS-UG彩の国埼玉 #12)
mhrtech
2
220
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
120
JAWSUG TOHOKU 青森支部 「LoGoチャット」のAWS移行で 乗り越えたこと
taketakekaho
0
330
実践!Cloud Run ハンズオン!! / Cloud Run handson
y0hgi
2
280
Featured
See All Featured
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
940
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
310
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
Navigating Team Friction
lara
192
16k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Visualization
eitanlees
153
17k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Skip the Path - Find Your Career Trail
mkilby
1
260
30 Presentation Tips
portentint
PRO
1
430
Are puppies a ranking factor?
jonoalderson
2
4.1k
Transcript
OkHttp3+Retrofit2+...
• Yoshihisa Takeda • @bomneko_attack • 株式会社Diverse(ミクシィグループ) • YYCというマッチングアプリの開発をしています •
Android開発をはじめてもうすぐ1年
APIを叩くAndroidアプリをつくるとき 通信部分を作り込むときにつかうライブラリ
OkHttp http://square.github.io/okhttp/
Retorofit http://square.github.io/retrofit/
None
None
None
コールバック地獄…!
ReactiveX(Rx)
Observable系(Single,Flowableなど)を返すように書く
Call<T>をRxJava2のObservable系に変換するCall Adapterを指定する
None
コールバック地獄からの解放…!
完
完?
できることならこう書きたくないですか?
Coroutine
OkHttp3+Retrofit2+Coroutine
Coroutine • 「中断・再開が可能な関数」 ◦ とりあえずの理解としては「軽量スレッド」的なもの • Kotlin1.1から実験的に導入された • Coroutinesをゼロから説明すると本1冊書けるぐらいになるので 本発表では導入とRetrofitでの使い方についてのみ
警告 • Kotlin CoroutineはKotlin1.2の時点ではExperimentalで提供 プロダクションへの導入はまだ控えたほうが安全 ◦ 1.3でExperimentalが外れる予定なので勉強をはじめるには良いタイミング ◦ 本資料の組み合わせは Kotlin
1.2 + kotlinx.coroutine 0.21.1
導入 • build.gradleに2つライブラリを追加 ◦ kotlin.coroutines=enable はいらない
Call Adapter • Jake神のCall Adapter ◦ 他にもう1つ見つけたけど今回はこれ ◦ Call<T>をCoroutineのDeferred<T>に変換する
Deferred<T>を返すように書く
Call<T>をCoroutineのDeferred<T>に変換するAdapterを指定
None
レスポンスが返ってくるまで中断 (UIスレッドはブロックされない )
Rxはいらない子になるのか? • No • RxがPromise代わり使われてきたという歴史 • コルーチンもPromiseを同期的に書く手法(async/await)を提供しているので勘違い しやすい • Rxは「リアクティブプログラミングのためのフレームワーク」なのでそもそも比較対象
にならない
まとめ • もうすぐくるかもしれないコルーチン時代に備えて勉強はしておこう • Jakeのライブラリを使えばOkHttpとRetrofitの組み合わせにおいてコルーチンを簡 単に導入でき使える! ◦ もう1つはこれ。どっちを使うかはお好みで … https://github.com/gildor/kotlin-coroutines-retrofit
宣伝 DiverseはDroidKaigi2018のPLATINUMスポンサーとして参加します 当日ブースで同人誌を無料配布します