1

I have the following items defined in my android application manifest

1 Application extension 3 Services 5 Activities

Is it guaranteed that the onCreate of my Application class complete before the services are started? I have specific logic that needs to occur before the three services are started to properly initialize the application state.

4

2 回答 2

2

That's at least how I understand the documentation:

public void onCreate()

"Called when the application is starting, before any other application objects 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."

http://developer.android.com/reference/android/app/Application.html#onCreate%28%29

于 2012-06-07T16:48:01.507 回答
0

Common sense suggests that it is. It's not explicitly documented IIRC. However, Service.getApplication() is not documented as capable of returning null, so I'd say - code as if it is.

Application init and service init both happen on the same UI thread, so don't worry about concurrency ("X begins before Y completes..."). There's no potential for a race condition, as a service is not a thread.

于 2012-06-07T16:48:27.847 回答