Android(Kotlin)

PeriodicWorkManager Unique Work

----___<<<<< 2022. 11. 21. 04:38

 

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val myWork = PeriodicWorkRequest.Builder(
            TestWorkManager::class.java,
            15,
            TimeUnit.MINUTES
        ).build()

        WorkManager.getInstance(this).enqueueUniquePeriodicWork(
            "GetCoinPriceRecentlyContractedWorkManager",
            ExistingPeriodicWorkPolicy.KEEP,
            myWork
        )

    }

}
class TestWorkManager(val context: Context, workerParameters: WorkerParameters) : CoroutineWorker(context, workerParameters){

    override suspend fun doWork(): Result {

        Log.d("TestWorkManager", "doWork")

        return Result.success()

    }


}
// Coroutine WorkManager
implementation("androidx.work:work-runtime-ktx:2.7.1")

 

 

 

 

'Android(Kotlin)' 카테고리의 다른 글

Android ListAdapter  (0) 2022.12.04
by viewModels()  (0) 2022.12.03
Android App Inspector  (1) 2022.11.12
Android Timber  (0) 2022.11.04
Andorid AlarmManager  (0) 2022.10.29