Is the Application class guaranteed to be instantiated before a defined boot receiver is called

后端 未结 2 1684
生来不讨喜
生来不讨喜 2021-01-12 13:20

Excuse me for such an elementary question. I understand that the Application class is instantiated when my app\'s process starts and I understand when the phone is complete

2条回答
  •  粉色の甜心
    2021-01-12 13:57

    Phone reboots, phone starts all processes with BOOT_COMPLETED, phone fires off BOOT_COMPLETED broadcast.

    I would phrase it more as "phone reboots, phone fires off BOOT_COMPLETED broadcast, and normal broadcast processing occurs, including starting any necessary processes".

    My concern came from wondering if I reference Application class instance variables within my boot receiver if the receiver would ever get called before my Application class was instantiated.

    It shouldn't. The order of instantiation is supposed to be:

    • any ContentProviders you have defined in your manifest, then

    • the Application instance, then

    • the component that triggered the need for the process (in this case, your ACTION_BOOT_COMPLETED BroadcastReceiver)

提交回复
热议问题