androidserviceandroid-serviceandroid-service-bindingandroid-application-class

Can I expect my application's constructor to get executed completely before my service methods are invoked?


Coming straight to question,

  1. App_A -> binds with service in App_B
  2. App_B tries to init few values in it's application class constructor

Can I expect App_B's Application class constructor to get executed completely before the service methods (constructor (or) onStart (or) onBind) within App_B starts getting executed?


Solution

  • Yup, that's true. The app will block until it finishes instantiating the Application class. So if you are doing a blocking operation in the Application's constructor or on the onCreate method, it will be executed before anything else inside your application. Just make sure that these operations are executed in the main thread and not in a background thread!