I use workmanager in appwidget with a separate process,
<receiver
android:name=".todo.calendar.appwidget.ScheduleWidgetSmall"
android:exported="true"
android:label="@string/schedule_widget_label"
android:process=":widgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="android.appwidget.action.APPWIDGET_UPDATE_NORMAL" />
<action android:name="android.appwidget.action.APPWIDGET_UPDATE_WORKER" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/schedule_app_widget_info_small" />
</receiver>
override fun onEnabled(context: Context?) {
super.onEnabled(context)
val constraints = Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build()
val workRequest: PeriodicWorkRequest = PeriodicWorkRequest.Builder(
ScheduleWidgetWorker::class.java,
15 * 60 * 1000L
, TimeUnit.MILLISECONDS)
.setConstraints(constraints)
.build()
if (context != null) {
WorkManager.getInstance(context).enqueueUniquePeriodicWork(getWorkerName(), ExistingPeriodicWorkPolicy.KEEP, workRequest)
}
}
but when add the appwidget to the screen, I got the error:
2023-06-07 14:58:42.145 30654-30654/com.xxx.xxx E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.xxx.xxx:widgetProvider, PID: 30654
java.lang.IllegalStateException: WorkManager is not initialized properly. You have explicitly disabled WorkManagerInitializer in your manifest, have not manually called WorkManager#initialize at this point, and your Application does not implement Configuration.Provider.
I don't disabled WorkManagerInitializer in manifest
workmanager version: 2.7.0
when I delete the android:process=":widgetProvider", the workmanager work well.