Closed mag0716 closed 5 years ago
初期化前に enqeue すると
2019-07-01 22:20:30.709 7385-7385/com.github.mag0716.workmanagersample.ondemandinitialization E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.github.mag0716.workmanagersample.ondemandinitialization, PID: 7385
java.lang.IllegalStateException: WorkManager is not initialized properly. The most likely cause is that you disabled WorkManagerInitializer in your manifest but forgot to call WorkManager#initialize in your Application#onCreate or a ContentProvider.
at androidx.work.WorkManager.getInstance(WorkManager.java:161)
at com.github.mag0716.workmanagersample.ondemandinitialization.MainActivity.startOneTimeWork(MainActivity.kt:29)
at com.github.mag0716.workmanagersample.ondemandinitialization.MainActivity.access$startOneTimeWork(MainActivity.kt:12)
at com.github.mag0716.workmanagersample.ondemandinitialization.MainActivity$onCreate$1.onClick(MainActivity.kt:21)
at android.view.View.performClick(View.java:7251)
at android.view.View.performClickInternal(View.java:7228)
at android.view.View.access$3500(View.java:802)
at android.view.View$PerformClick.run(View.java:27843)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7116)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925)
でクラッシュする。
概要
WorkManager の初期化を必要になってから行うことでアプリ起動時のパフォーマンスを改善する
参考
https://developer.android.com/topic/libraries/architecture/workmanager/advanced/custom-configuration#on-demand