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
380
Shibuya.apk_41_DeepDiveintoRememberSaveable.pdf
yurihondo
April 21, 2023
Tweet
Share
More Decks by yurihondo
See All by yurihondo
YouTubeへのライブ配信機能をリリースするまで
yurihondo
0
1.7k
Composeでシステムオーバーレイ / System overlay in Compose
yurihondo
0
220
Service由来のViewでViewModelを使えるようにしてみた
yurihondo
2
520
瀕死のシステムが強くなって復活する話
yurihondo
1
480
New UI Design & Debugging Tools In Android Studio
yurihondo
0
650
外部デバイスと密に連携するAndroidアプリに最適なアーキテクチャとは?
yurihondo
0
14k
Behavior of nested async in Kotlin Coroutines
yurihondo
2
1.1k
Other Decks in Programming
See All in Programming
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
270
try! Swift Tokyo 初参加報告LT
hinakko2
0
220
2 週間で Twitter Bot を作ってみた
contour_gara
0
580
1BRC--Nerd Sniping the Java Community
gunnarmorling
0
340
[技育CAMPアカデミア]アイディアを形に!【超入門】スマホアプリ開発〜リリースまでの流れをご紹介
teamlab
PRO
0
380
コーンフレークから始める モデリング会話入門
ogurotakayuki
0
380
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
170
⼤規模⾔語モデルの拡張(RAG)が 終わったかも知れない件について
nearme_tech
23
15k
0→1と1→10の狭間で Javaという技術選定を振り返る/Reflecting on the Decision to Choose Java Between Scaling from 0 to 1 and 1 to 10
jaguar_imo
2
380
VSCodeでのDatabricks開発もお勧めしたい/I would also recommend Databricks development with VSCode.
kazumain
0
260
二郎系ラーメンのコールで学ぶ AST 解析
memory1994
PRO
7
1.7k
雑に思考を整理する技術と効能
konifar
60
29k
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
Bash Introduction
62gerente
604
210k
From Idea to $5000 a Month in 5 Months
shpigford
377
45k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Stop Working from a Prison Cell
hatefulcrawdad
266
19k
Fantastic passwords and where to find them - at NoRuKo
philnash
37
2.5k
Bootstrapping a Software Product
garrettdimon
PRO
302
110k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
227
130k
Gamification - CAS2011
davidbonilla
76
4.6k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
25
2.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!