Android(Kotlin)

Android PeriodicWorkRequest Memo

----___<<<<< 2022. 4. 7. 12:14

 

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val request = PeriodicWorkRequest.Builder(SimplePeriodicWorker::class.java,
            24, TimeUnit.HOURS,
            15, TimeUnit.MINUTES)
            .build()
        WorkManager.getInstance(this).enqueue(request)

        val sendLogsWorkRequest = PeriodicWorkRequestBuilder<SimplePeriodicWorker>(24, TimeUnit.HOURS)
                .setConstraints(Constraints.Builder()
                    .setRequiresCharging(true)
                    .build()
                )
                .build()

        WorkManager.getInstance(this).enqueueUniquePeriodicWork(
            "dozeModeSending",
            ExistingPeriodicWorkPolicy.KEEP,
            sendLogsWorkRequest
        )

    }
}

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

Android REQUEST_IGNORE_BATTERY_OPTIMIZATIONS  (0) 2022.04.29
기존 Retrofit Callback 계속 붙이면?  (0) 2022.04.13
WorkManager Chaining  (0) 2022.03.30
Android Log가 안뜰 때  (0) 2022.03.18
RecyclerView Example  (0) 2022.03.09