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.5k
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
680
外部デバイスと密に連携するAndroidアプリに最適なアーキテクチャとは?
yurihondo
0
14k
Behavior of nested async in Kotlin Coroutines
yurihondo
2
1.1k
Other Decks in Programming
See All in Programming
sappoRo.R #12 初心者セッション
kosugitti
0
260
個人アプリを2年ぶりにアプデしたから褒めて / I just updated my personal app, praise me!
lovee
0
350
仕様変更に耐えるための"今の"DRY原則を考える / Rethinking the "Don't repeat yourself" for resilience to specification changes
mkmk884
2
450
昭和の職場からアジャイルの世界へ
kumagoro95
1
380
Pythonでもちょっとリッチな見た目のアプリを設計してみる
ueponx
1
570
Open source software: how to live long and go far
gaelvaroquaux
0
640
GitHub Actions × RAGでコードレビューの検証の結果
sho_000
0
270
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
47
17k
2,500万ユーザーを支えるSREチームの6年間のスクラムのカイゼン
honmarkhunt
6
5.3k
苦しいTiDBへの移行を乗り越えて快適な運用を目指す
leveragestech
0
630
Honoのおもしろいミドルウェアをみてみよう
yusukebe
1
210
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
130
Featured
See All Featured
Designing for Performance
lara
604
68k
Building Your Own Lightsaber
phodgson
104
6.2k
Scaling GitHub
holman
459
140k
A Tale of Four Properties
chriscoyier
158
23k
Code Reviewing Like a Champion
maltzj
521
39k
Visualization
eitanlees
146
15k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.8k
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!