gpt4 book ai didi

java - WorkManager 自定义初始化提示 WorkManager#initialize

转载 作者:行者123 更新时间:2023-12-04 23:55:09 26 4
gpt4 key购买 nike

与:实现“androidx.work:work-runtime:2.3.4”

我正在尝试实现自定义初始化以启用更详细的日志记录 according to these instructions .

第一个 fragment 有一行错误:return Configuration.Builder() 需要是 return new Configuration.Builder()

我扩展了应用程序,如下所示:

class MyApplication extends Application implements Configuration.Provider {
@Override
public Configuration getWorkManagerConfiguration() {
return new Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.INFO)
.build();
}
}

我这样启动 worker:

WorkManager.getInstance(getApplicationContext());

但即使在所有这些之后,我的应用程序也因以下投诉而崩溃:

WorkManager is not initialized properly. You have explicitly disabledWorkManagerInitializer in your manifest, have not manually calledWorkManager#initialize at this point, and your Application does notimplement Configuration.Provider.

尽管说明中指出:

You do not need to call WorkManager.initialize() yourself

最佳答案

请引用此链接: https://developer.android.com/topic/libraries/architecture/workmanager/advanced/custom-configuration#custom

像这样初始化您的自定义 WorkManager:

// provide custom configuration
val myConfig = Configuration.Builder()
.setMinimumLoggingLevel(android.util.Log.INFO)
.build()

// initialize WorkManager
WorkManager.initialize(this, myConfig)

关于java - WorkManager 自定义初始化提示 WorkManager#initialize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62510031/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com