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
65
Applicationクラスのライフサイクル に気をつけよう
gotlin
November 15, 2024
Tweet
Share
More Decks by gotlin
See All by gotlin
Conference-app-2024の良さげな実装を勝手にいくつか紹介する
goutarouh
0
58
VRTをプロダクトに導入するまでのお話
goutarouh
0
310
Drag & Drop in LazyColumn
goutarouh
0
860
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Optimising Largest Contentful Paint
csswizardry
37
3.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.4k
Thoughts on Productivity
jonyablonski
69
4.7k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
7
330
Building Adaptive Systems
keathley
43
2.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Pragmatic Product Professional
lauravandoore
35
6.7k
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