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
55
Applicationクラスのライフサイクル に気をつけよう
gotlin
November 15, 2024
Tweet
Share
More Decks by gotlin
See All by gotlin
Conference-app-2024の良さげな実装を勝手にいくつか紹介する
goutarouh
0
48
VRTをプロダクトに導入するまでのお話
goutarouh
0
270
Drag & Drop in LazyColumn
goutarouh
0
800
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
BBQ
matthewcrist
87
9.5k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.5k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Faster Mobile Websites
deanohume
306
31k
The Pragmatic Product Professional
lauravandoore
32
6.4k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
11
1.3k
Building an army of robots
kneath
303
45k
The Language of Interfaces
destraynor
156
24k
Practical Orchestrator
shlominoach
186
10k
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