How to ensure app is fully initialized before WorkManager does work?

I have work scheduled. When my app is not running the WorkManager wakes up my app. How do I ensure that my app is fully initialized before WorkManager does any of the work?

class UploadWorker(appContext: Context, workerParams: WorkerParameters):
       Worker(appContext, workerParams) {
   override fun doWork(): Result {


       return Result.success()

Manager is an object that requires Room and other classes to be initialized by the Application class.

1 answer

  • answered 2021-01-11 06:09 i30mb1

    An application is started when one of it's components is initialed for execution. Any component can be entry point for the application, and once the fist component is triggered to start, a Linux process is started (unless it is already running) leading to the following startup sequence :

    1. Start Linux process
    2. Create runtime
    3. Create Application instance
    4. Create the entry point component for the application

    So if you initialize your Room and others classes in Application synchronously you can be fully sure that all your instance will be available in WorkManager