我想开始Django使用Celery. 以下是我的项目的相关部分:
# celery.py
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bookProjectSetting.settings')
app = Celery('bookProjectSetting')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')
Run Code Online (Sandbox Code Playgroud)
该 …
我想将 WorkManager 与 Hilt 一起使用。我按照文档并将所需的依赖项集成到我的 gradle 文件中:
// WorkManager library
implementation "androidx.work:work-runtime-ktx:$work_version"
// To use WorkManager with Hilt
implementation "androidx.hilt:hilt-work:workmanager_hilt_version"
// Annotation processor when using Kotlin
kapt "androidx.hilt:hilt-compiler:workmanager_hilt_version"
Run Code Online (Sandbox Code Playgroud)
请注意,版本是work_version = "2.5.0"和workmanager_hilt_version = "1.0.0-beta01"。
然后我转到我的 Worker 类并按照@HiltWorker文档中的描述输入,但 Android Studio 找不到它:
@HiltWorker
class RefreshDataWorker @AssistedInject constructor(@Assisted appContext: Context, @Assisted params: WorkerParameters): CoroutineWorker(appContext, params) { ...// some doWork() stuff }
Run Code Online (Sandbox Code Playgroud)
@HiltWorker是红色字母,Android Studio 找不到它。为什么 ?做某事。希尔特发生了变化?有没有什么。文档中缺少?
我希望有人能帮帮忙。
在我的 Android 应用程序中,我使用Room本地数据库来存储用户的帐户信息。当我发出一个简单的Room请求来检索Account存储在数据库中的对象时,我收到以下错误消息:
java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
Run Code Online (Sandbox Code Playgroud)
这是Fragment我发出本地数据库请求的代码:
// AccountInformationFragment.kt
accountDataFragmentViewModel.retrieveAccountData(accountId).observe(viewLifecycleOwner, Observer {
// do some stuff
})
Run Code Online (Sandbox Code Playgroud)
在ViewModel课堂上我是这样实现的retrieveAccountData():
// AccountInformationFragmentViewModel.kt
// used to get the account from the local datasource
fun retrieveAccountData(id:Long): LiveData<Account>{
val result = MutableLiveData<Account>()
viewModelScope.launch {
val account = authRepository.retrieveAccountData(id)
result.postValue(account)
}
return result
}
Run Code Online (Sandbox Code Playgroud)
在Repository …
android illegalstateexception android-room kotlin-coroutines