Android 计划稍后执行的任务(时间和日期)
我只需搜索允许我在计时器(具有特定日期和时间)完成后(以Kotlin格式)执行操作的代码,并将其保存在列表中 喜欢在Twitter上发布推文的计时器: 您可以使用它 依赖关系:Android 计划稍后执行的任务(时间和日期),android,kotlin,timer,schedule,Android,Kotlin,Timer,Schedule,我只需搜索允许我在计时器(具有特定日期和时间)完成后(以Kotlin格式)执行操作的代码,并将其保存在列表中 喜欢在Twitter上发布推文的计时器: 您可以使用它 依赖关系: implementation "androidx.work:work-runtime-ktx:2.3.0" class LogWorker(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {
implementation "androidx.work:work-runtime-ktx:2.3.0"
class LogWorker(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {
override fun doWork(): Result {
// Do the work here--in this case, upload the images.
Log.i("ToastWorker", "doWork: Working ⚒ ⚒ ⚒")
// Indicate whether the task finished successfully with the Result
return Result.success()
}
}
示例:
implementation "androidx.work:work-runtime-ktx:2.3.0"
class LogWorker(appContext: Context, workerParams: WorkerParameters) : Worker(appContext, workerParams) {
override fun doWork(): Result {
// Do the work here--in this case, upload the images.
Log.i("ToastWorker", "doWork: Working ⚒ ⚒ ⚒")
// Indicate whether the task finished successfully with the Result
return Result.success()
}
}
然后设置延迟时间
val logWorkRequest = OneTimeWorkRequestBuilder<LogWorker>()
.setInitialDelay(5, TimeUnit.SECONDS) // here you can set the delay time in Minutes, Hours
.build()
这里有一个更深入的例子。你也可以