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
66
Applicationクラスのライフサイクル に気をつけよう
gotlin
November 15, 2024
Tweet
Share
More Decks by gotlin
See All by gotlin
Conference-app-2024の良さげな実装を勝手にいくつか紹介する
goutarouh
0
62
VRTをプロダクトに導入するまでのお話
goutarouh
0
320
Drag & Drop in LazyColumn
goutarouh
0
880
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.5k
Scaling GitHub
holman
463
140k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
Typedesign – Prime Four
hannesfritz
42
2.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.1k
Fireside Chat
paigeccino
39
3.6k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
Building an army of robots
kneath
306
46k
The World Runs on Bad Software
bkeepers
PRO
70
11k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
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