Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Shibuya.apk_41_DeepDiveintoRememberSaveable.pdf
Search
yurihondo
April 21, 2023
Programming
0
430
Shibuya.apk_41_DeepDiveintoRememberSaveable.pdf
yurihondo
April 21, 2023
Tweet
Share
More Decks by yurihondo
See All by yurihondo
Road to Single Activity Uncovered
yurihondo
0
140
Road to Single Activity
yurihondo
2
570
YouTubeへのライブ配信機能をリリースするまで
yurihondo
0
2.6k
Composeでシステムオーバーレイ / System overlay in Compose
yurihondo
0
310
Service由来のViewでViewModelを使えるようにしてみた
yurihondo
2
600
瀕死のシステムが強くなって復活する話
yurihondo
1
500
New UI Design & Debugging Tools In Android Studio
yurihondo
0
690
外部デバイスと密に連携するAndroidアプリに最適なアーキテクチャとは?
yurihondo
0
14k
Behavior of nested async in Kotlin Coroutines
yurihondo
2
1.1k
Other Decks in Programming
See All in Programming
お前もAI鬼にならないか?👹Bolt & Cursor & Supabase & Vercelで人間をやめるぞ、ジョジョー!👺
taishiyade
7
4.2k
Honoをフロントエンドで使う 3つのやり方
yusukebe
7
3.6k
機能が複雑化しても 頼りになる FactoryBotの話
tamikof
1
230
DevNexus - Create AI Infused Java Apps with LangChain4j
kdubois
0
130
「個人開発マネタイズ大全」が教えてくれたこと
bani24884
1
290
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
1.2k
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
5
1.1k
TCAを用いたAmebaのリアーキテクチャ
dazy
0
220
AIプログラミング雑キャッチアップ
yuheinakasaka
19
5k
PRレビューのお供にDanger
stoticdev
1
240
AIレビュー導入によるCIツールとの共存と最適化
kamo26sima
1
210
Honoのおもしろいミドルウェアをみてみよう
yusukebe
1
240
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
32
6.4k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Making Projects Easy
brettharned
116
6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
21
2.5k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Docker and Python
trallard
44
3.3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.5k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
10
530
Transcript
Deep Dive into RememberSaveable
yurihondo 2 HELLO! Software Engineer@U-NEXT とにかく家が欲しい。 いい物件があったら教えてください。 Twitter : yurihondo
@yuyuyuyuyuri
Agenda 3 » Background » Understanding the Inner Workings »
How to Customize
BACKGROUND 4 1.
Background Composeを使っていると アプリ パフォーマンスについて課題が発生すること がたま〜にある 5
Background 弊チーム 場合、 Nexusなど 少し前()に発売された端末などで アプリ パフォーマンス劣化が顕著だった 6
Background インスタンス化 処理が原因 一つ 7
Background 8 https://speakerdeck.com/tomoya0x00/compose-false-lazycolumn-pahuomansugai-shan-dequ-rizu-ndakoto
Background 保存するオブジェクトが多いシチュエーションに おいて 、 RememberXxxなどを利用する際、 どこにキャッシュされる かを 気にした方が良い (大体 アプリ
気にしなくて良い) 9
Background rememberSaveable 保存先(SavedState)に 、 保存量に制限がある 10
Background Bundleな でMax 1MB…と思いきや、 11 https://developer.android.com/guide/components/activities/parcelables-and-bundles
Background SavedStateについて 、 50KB以上保存する 避けた方が良さそう 12
Background なんか前 大丈夫だった気がする... と思ったら、M以前 Warningだったらしい 13
Background 14 今 使い勝手を維持しつつ なんとかならん か?
Understanding the Inner Workings 15 2.
Background 16 ここから 発表内容 Androidx.compose.runtime:runtime-saveable: 1.4.0 環境ベースです
RememberSaveable Understanding the Inner Workings 17
RememberSaveable Understanding the Inner Workings 18 データ 保存や復元時に ペアになるKeyを生成
RememberSaveable Understanding the Inner Workings 19 SaveableStateRegistryからKeyを元に 保存していたデータを取り出す
RememberSaveable Understanding the Inner Workings 20 データや保存/復元を担う処理 変更 を監視
RememberSaveable Understanding the Inner Workings 21
RememberSaveable Understanding the Inner Workings 22 保存処理 Lambdaを SaveableStateRegistryへ登録
RememberSaveable Understanding the Inner Workings 23 Compositionを抜ける時に、 登録した保存処理を消す
RememberSaveable Understanding the Inner Workings 24 Compositionを抜ける時に、 登録した保存処理を消す
Understanding the Inner Workings 25
Understanding the Inner Workings 26 これを知りたい
Understanding the Inner Workings 27 SaveableStateRegistry
SaveableStateRegistry Understanding the Inner Workings 28 » SavedInstanceState 仕組みを利用 してデータ
保存・復元をする » 保存するデータを生成するLambdaを 管理(登録、登録解除)する » データがこ 仕組みで保存可能なも かを判定する
SaveableStateRegistry Understanding the Inner Workings 29 » SavedInstanceState 仕組みを利用 してデータ
保存・復元をする » 保存するデータを生成するLambdaを 管理(登録、登録解除)する » データがこ 仕組みで保存可能なも かを判定する データ 保存 これをトリガーしているところを知りたい
Understanding the Inner Workings 30 SaveableStateRegistryを 実装している
Understanding the Inner Workings 31
Understanding the Inner Workings 32 注目すべき DisposableSaveableStateRegistory
Understanding the Inner Workings 33 ComposeViewがActivityなどに Attachされた時に呼 れ、 Composition Localに設定される
Disposable SaveableStateRegistory Understanding the Inner Workings 34 SavedStateRegistoryOwnerから SavedStateRegistoryを取得 keyを元に保存したデータを取得
Understanding the Inner Workings 35 SavedStateRegistoryに SaveableStateRegitoryが管理している 保存対象データ 取得処理を渡す Disposable
SaveableStateRegistory
Understanding the Inner Workings 36 Activity#onSaveInstanceState タイミングで実行される
Understanding the Inner Workings 37 disposeが呼 れたタイミングで解除 Disposable SaveableStateRegistory
Understanding the Inner Workings 38 まとめると
Understanding the Inner Workings 39
Understanding the Inner Workings 40
Activity Composable Understanding the Inner Workings 41 RememberSaveable SaveableStateRegitory (DisposableSaveableStateRegistory)
SavedStateRegitory
Understanding the Inner Workings 42 仕組み わかった これを応用すると...
How to Customize 43 3.
Activity Composable Understanding the Inner Workings 44 RememberSaveable SaveableStateRegitory (DisposableSaveableStateRegistory)
SavedStateRegitory
Activity Composable Understanding the Inner Workings 45 RememberSaveable SaveableStateRegitory (DisposableSaveableStateRegistory)
SavedStateRegitory
Activity Composable Understanding the Inner Workings 46 RememberSaveable SaveableStateRegitory (DisposableSaveableStateRegistory)
SaveStateRegitory 保存方法を変えれ 保存先を変更できる
Understanding the Inner Workings 47 試しに作ってみよう
Activity Composable Understanding the Inner Workings 48 RememberSaveable SaveableStateRegitory (DisposableSaveableStateRegistory)
SavedStateRegitory
How to Customize 49
How to Customize 50 SavedStateRegistoryに相当するI/F
How to Customize 51 単純に データ 保存領域として stateMap State 提供方法としてproviders
を保持
How to Customize 52
How to Customize 53
Activity Composable Understanding the Inner Workings 54 RememberSaveable SaveableStateRegitory (DisposableSaveableStateRegistory)
SaveStateRegitory
How to Customize 55
How to Customize 56 自前で用意したSavedStateRegistoryを取得
How to Customize 57 メイン 処理 Framework 実装に任せる
How to Customize 58
How to Customize 59 Composition Localに設定
How to Customize 60
How to Customize 61 自作 SavedStateRegistory Onwerを 実装、保存先を提供
How to Customize 62 OnSaveInstanceStateで保存をトリガーしておく
How to Customize 63 自作 SaveableStateRegistoryを提供
Understanding the Inner Workings 64 …特に必要性がない場合 、 いつも通りSavedStateに 保存したいよなぁ
Understanding the Inner Workings 65 rememberSaveableと 同じような仕組み自体を つくった方が良い で
Activity Composable Understanding the Inner Workings 66 RememberSaveable SaveableStateRegitory (DisposableSaveableStateRegistory)
SaveStateRegitory つまり 第3 Remember を作れ ...
Understanding the Inner Workings 67 GitHubにサンプル上げている で 必要に応じてご活用ください。 https://github.com/yurihondo/OutlawRemember/tree/main/sample/src/main/java/com/ yurihondo/outlawremember/sample
Any questions? You can find me at: » @yuyuyuyuyuri on
Twitter 68 THANKS!