question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception when not initialized in Application.onCreate

See original GitHub issue

I have a use case in which I can’t initialize JobManager in Application.onCreate (I’m using android-job in a library and I don’t have access to the application’s Application class).

Now, if I schedule a job which is run after the application closes, the job will be run without initializing JobManager and I will get the exception:

IllegalStateException: You need to call create() at least once to create the singleton

This can easily be solved if JobManager is created before being used in PlatformJobService.onStartJob using the service context if the singleton doesn’t already exist. Could you add this change to the project? I could do it myself if you approve.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:7

github_iconTop GitHub Comments

2reactions
vRallevcommented, Jul 25, 2016

Fixed in version 1.0.10. Thanks for your feedback!

1reaction
akramShokricommented, Jul 23, 2016

If for example I call JobCreator in Activity.onCreate, the JobManager will call my JobCreator form then on and jobs are scheduled and run. The problem is when application is not running, this exception (IllegalStateException) is raised. I may initialize JobCreator in a service so as it exists even when app is closed but if user force-close the app, this exception will happen again. As I cannot prevent occurrence of this exception in this scenario, I need this exception to not happen. At least even f my jobs are not running, the app still can have its normal behaviour. @vRallev

Read more comments on GitHub >

github_iconTop Results From Across the Web

WorkManager not initialized exception even though ...
lang. IllegalStateException: WorkManager is not initialized properly. The most likely cause is that you disabled WorkManagerInitializer in your ...
Read more >
Crash on device that FBE is enabled [112665532]
2nd exception: java.lang.IllegalStateException: WorkManager needs to be initialized via a ContentProvider#onCreate() or an Application#onCreate(). I'm ...
Read more >
Custom Work Manager initialization | by Michael Spitsin
Aforementioned exception happens because of 2 reasons that present in the project simultaneously: ... As we have multi process application, each ...
Read more >
Custom WorkManager Configuration and Initialization
Make sure the initialization of the WorkManager singleton runs either in Application.onCreate() ...
Read more >
Modularization of Android Applications with lazy initialization
One more important thing. Modules are not initialized here, i.e. inner components are not created immediately inside Application.onCreate().
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found