Having these dependencies:
dependencies {
implementation "androidx.work:work-runtime:2.0.1"
androidTestImplementation "androidx.work:work-testing:2.0.1"
}
When running this code for the second time:
Configuration config = new Configuration.Builder().build();
WorkManager.initialize(getApplicationContext(), config);
this.workManager = WorkManager.getInstance();
I get this error message:
java.lang.IllegalStateException: WorkManager is already initialized.
Did you try to initialize it manually without disabling WorkManagerInitializer?
See WorkManager#initialize(Context, Configuration) or the class level Javadoc for more information.
and it also throws a segmentation fault on the native side:
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR),
fault addr 0x878 in tid 10892 (ova.workmanager),
pid 10892 (ova.workmanager)
This would be the documentation for WorkManager#initialize(Context, Configuration)
.
The intent is to prevent the crash during manual initialization (in order to change the log level). How to disable the WorkManagerInitializer
? If possible, I do not want to use the static
keyword.
.getInstance()
is astatic
method and not an instance method. that answer is just an approach I've found, based upon the suggestion in the error message; still need to test that (the blog post is only a similar situation). – DisrememberApplication#onCreate
as suggested in the official guide (just below the code block). After that, use the staticgetInstance
freely anywhere in your code because theWorkManager
had already been initialized. – Hankypanky