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
54
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
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
Embracing the Ebb and Flow
colly
84
4.5k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Site-Speed That Sticks
csswizardry
3
300
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Agile that works and the tools we love
rasmusluckow
328
21k
How STYLIGHT went responsive
nonsquared
96
5.3k
Scaling GitHub
holman
459
140k
Typedesign – Prime Four
hannesfritz
40
2.5k
It's Worth the Effort
3n
184
28k
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