Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 计划稍后执行的任务(时间和日期)_Android_Kotlin_Timer_Schedule - Fatal编程技术网

Android 计划稍后执行的任务(时间和日期)

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) {

我只需搜索允许我在计时器(具有特定日期和时间)完成后(以Kotlin格式)执行操作的代码,并将其保存在列表中

喜欢在Twitter上发布推文的计时器:

您可以使用它

依赖关系:

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()
这里有一个更深入的例子。你也可以