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
Applicationクラスのライフサイクルに気をつけよう
Search
gotlin
November 15, 2024
0
50
Applicationクラスのライフサイクル に気をつけよう
gotlin
November 15, 2024
Tweet
Share
More Decks by gotlin
See All by gotlin
Conference-app-2024の良さげな実装を勝手にいくつか紹介する
goutarouh
0
48
VRTをプロダクトに導入するまでのお話
goutarouh
0
260
Drag & Drop in LazyColumn
goutarouh
0
790
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
4
190
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
970
Optimising Largest Contentful Paint
csswizardry
33
3k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
A Philosophy of Restraint
colly
203
16k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
How GitHub (no longer) Works
holman
312
140k
Transcript
1 Applicationクラスのライフサイクル に気をつけよう KINTOテクノロジーズ株式会社 長谷川
2 自己紹介 ・2022/9~ 入社 ・myroute Android開発TL ・バイク好き George(あだ名) 長谷川剛太(gota hasegawa)
X: @kotlinan
3 今日話すこと ・Applicationクラスのライフサイクルに気をつけよう!
4 Applicationクラスのライフサイクルに気をつけろ! class MyApplication: Application() { override fun onCreate() {
super.onCreate() } } <!– AndroidManifest.xml --> <application android:name=".MyApplication"> <activity android:name=".MyActivity" /> </application>
5 Applicationクラスのライフサイクルに気をつけろ! @HiltAndroidApp class MyApplication: Application() { override fun onCreate()
{ super.onCreate() // ライブラリ初期化 // APIコール } }
6 Applicationクラスのライフサイクルに気をつけろ! 昔の話 ・サーバーが落ちたと連絡を受ける ・バックエンドチームがやらかしてしまったのかとスルー ・Androidアプリから通信数が急激に増加したことが原因だったらしい (何かの間違いだ、ミスを認めたくない) ・どうやらユーザーに通知を送ったタイミングで問題が起きている ・心当たりがある気がする…
7 Applicationクラスのライフサイクルに気をつけろ! class MyApplication: Application() { override fun onCreate() {
super.onCreate() // ライブラリ初期化 // APIコール } }
8 Applicationクラスのライフサイクルに気をつけろ! @HiltAndroidApp class MyApplication: Application() { override fun onCreate()
{ super.onCreate() // ライブラリ初期化 // APIコール } }
9 Applicationクラスのライフサイクルに気をつけろ! ユーザーがアプリを開かなくても APIコールされます
10 Applicationクラスのライフサイクルに気をつけろ! Android4大要素 Activity Content Provider Service Broadcast Receiver
11 Applicationクラスのライフサイクルに気をつけろ! Android4大要素 Activity Service Broadcast Receiver Content Provider Screen
etc.
12 Applicationクラスのライフサイクルに気をつけろ! Android4大要素 Activity Service Broadcast Receiver Content Provider Notification
etc. Screen etc.
13 Applicationクラスのライフサイクルに気をつけろ! Android4大要素 Activity Service Broadcast Receiver Content Provider Notification
etc. Widget etc. Screen etc.
14 Applicationクラスのライフサイクルに気をつけろ! Android4大要素 Activity Service Broadcast Receiver Content Provider Notification
etc. Widget etc. Screen etc. Data access etc.
15 Applicationクラスのライフサイクルに気をつけろ! Android4大要素 Activity Service Application Broadcast Receiver Content Provider
Notification etc. Widget etc. Screen etc. Data access etc.
16 Applicationクラスのライフサイクルに気をつけろ! Android4大要素 Activity Notification etc. Widget etc. Application Screen
etc. アプリは 開いていない Data access etc. Service Broad Cast Receiver Content Provider
17 Applicationクラスのライフサイクルに気をつけろ! 画面が開いていなくても アプリケーションクラスは呼ばれる?
18 Applicationクラスのライフサイクルに気をつけろ! Widgetを作成 @AndroidEntryPoint class MyWidgetReceiver : GlanceAppWidgetReceiver() { ...
} <!- AndroidManifest.xml --> <receiver android:name=".MyWidgetReceiver" > </receiver> https://developer.android.com/develop/ui/views/appwidgets/layouts
19 Applicationクラスのライフサイクルに気をつけろ! Widgetを作成 @AndroidEntryPoint class MyWidgetReceiver : GlanceAppWidgetReceiver() { ...
} <!- AndroidManifest.xml --> <receiver android:name=".MyWidgetReceiver" > </receiver> BroadcastReceiver https://developer.android.com/develop/ui/views/appwidgets/layouts
20 Applicationクラスのライフサイクルに気をつけろ! Widgetを作成したときに Application#onCreate() が呼ばれる可能性がある
21 Applicationクラスのライフサイクルに気をつけろ! 通知を送信 <!- AndroidManifest.xml --> <service android:name="MyNotificationService"> </service> class
MyNotificationService : FirebaseMessagingService() { ... } https://developer.android.com/develop/ui/views/notifications
22 Applicationクラスのライフサイクルに気をつけろ! 通知を送信 class MyNotificationService : FirebaseMessagingService() { ... }
Service <!- AndroidManifest.xml --> <service android:name="MyNotificationService"> </service> https://developer.android.com/develop/ui/views/notifications
23 Applicationクラスのライフサイクルに気をつけろ! 通知を受け取ったときに Application#onCreate() が呼ばれる可能性がある
24 Applicationクラスのライフサイクルに気をつけろ! @HiltAndroidApp class MyApplication: Application() { override fun onCreate()
{ super.onCreate() // 初期化 // APIコール } }
25 Applicationクラスのライフサイクルに気をつけろ! 通知を出すと数万個のAPIコールを ほぼ同時に呼び出すリスクがある
26 Applicationクラスのライフサイクルに気をつけろ! ・Application#onCreateでの高負荷な処理は避ける ・Applicationやそれぞれのコンポーネントのライフサイクルを意識する ・HiltでDIするときのコンポーネントのライフサイクルを意識する ・通知を出すタイミングはグループ分割する
None