When does Application's onCreate() method get called?

后端 未结 3 1439
傲寒
傲寒 2020-12-01 04:50

In my Android application, I have a DefaultApplication class which extends android.app.Application, and in its onCreate() I bind some

相关标签:
3条回答
  • 2020-12-01 05:24

    Only the first time.

    When Activity is started and application is not loaded, then both onCreate() methods will be called.

    But for subsequent starts of Activity, the onCreate() of application will not be called.

    0 讨论(0)
  • 2020-12-01 05:29

    You can find an official answer when onCreate is called here.

    Called when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created. Implementations should be as quick as possible (for example using lazy initialization of state) since the time spent in this function directly impacts the performance of starting the first activity, service, or receiver in a process. If you override this method, be sure to call super.onCreate().

    0 讨论(0)
  • 2020-12-01 05:43

    Note that if any service is defined to run in other process e.g. with android:process= then Application's onCreate() will be called again for that process.

    For example see Android Application class method onCreate being called multiple times

    0 讨论(0)
提交回复
热议问题