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
400
Shibuya.apk_41_DeepDiveintoRememberSaveable.pdf
yurihondo
April 21, 2023
Tweet
Share
More Decks by yurihondo
See All by yurihondo
Road to Single Activity
yurihondo
1
240
YouTubeへのライブ配信機能をリリースするまで
yurihondo
0
2.2k
Composeでシステムオーバーレイ / System overlay in Compose
yurihondo
0
250
Service由来のViewでViewModelを使えるようにしてみた
yurihondo
2
540
瀕死のシステムが強くなって復活する話
yurihondo
1
490
New UI Design & Debugging Tools In Android Studio
yurihondo
0
670
外部デバイスと密に連携するAndroidアプリに最適なアーキテクチャとは?
yurihondo
0
14k
Behavior of nested async in Kotlin Coroutines
yurihondo
2
1.1k
Other Decks in Programming
See All in Programming
Using Livebook to build and deploy internal tools @ ElixirConf 2024
hugobarauna
0
250
Why Prism?
kddnewton
4
1.7k
事業フェーズの変化に対応する 開発生産性向上のゼロイチ
masaygggg
0
200
マルチモジュールにおけるテスト最適化
fxwx23
0
210
Some more adventure of Happy Eyeballs
coe401_
2
190
意外とフォントが大事だった話 / Font Issues on Internationalization
fumi23
0
110
From Idea to IDE: Developing Plugins for Android Studio
thisaay
1
220
Kotlin 2.0が与えるAndroid開発の進化
masayukisuda
1
410
【TID2024】模擬講義:プログラマと一緒にゲームをデザインしてみよう!
akatsukigames_tech
0
650
Lessons by WebAssembly app in production on CDN Edge Computing Service
tetsuharuohzeki
0
210
GenU導入でCDKに初挑戦し、悪戦苦闘した話
hideg
0
160
GraphQL あるいは React における自律的なデータ取得について
quramy
11
3k
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
517
39k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
123
18k
Creatively Recalculating Your Daily Design Routine
revolveconf
215
12k
Designing on Purpose - Digital PM Summit 2013
jponch
114
6.8k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.3k
Bash Introduction
62gerente
608
210k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
103
48k
Build your cross-platform service in a week with App Engine
jlugia
228
18k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
230
17k
BBQ
matthewcrist
83
9.2k
The Power of CSS Pseudo Elements
geoffreycrofte
71
5.3k
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!