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

泪湿孤枕 提交于 2019-11-27 18:56:45

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.

Ashwin N Bhanushali

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().

Paul Verest

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!