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
560
YouTubeへのライブ配信機能をリリースするまで
yurihondo
0
2.5k
Composeでシステムオーバーレイ / System overlay in Compose
yurihondo
0
280
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
Grafana Loki によるサーバログのコスト削減
mot_techtalk
1
110
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
2
470
SpringBoot3.4の構造化ログ #kanjava
irof
2
910
富山発の個人開発サービスで日本中の学校の業務を改善した話
krpk1900
4
360
[JAWS-UG横浜 #80] うわっ…今年のServerless アップデート、少なすぎ…?
maroon1st
1
160
Pulsar2 を雰囲気で使ってみよう
anoken
0
210
第3回 Snowflake 中部ユーザ会- dbt × Snowflake ハンズオン
hoto17296
4
340
ASP. NET CoreにおけるWebAPIの最新情報
tomokusaba
0
320
『品質』という言葉が嫌いな理由
korimu
0
140
Terraform で作る Amazon ECS の CI/CD パイプライン
hiyanger
0
140
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
3
1.2k
Linux && Docker 研修/Linux && Docker training
forrep
23
4.4k
Featured
See All Featured
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
3
300
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Designing on Purpose - Digital PM Summit 2013
jponch
117
7.1k
We Have a Design System, Now What?
morganepeng
51
7.4k
Speed Design
sergeychernyshev
25
780
Why Our Code Smells
bkeepers
PRO
335
57k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
20
2.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.4k
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!