간단한 예제를 만들어봤습니다.
A1
class MyWorker_A_1 (appContext : Context, workerParams: WorkerParameters) : CoroutineWorker(appContext,workerParams){
private val TAG = MyWorker_A_1::class.java.simpleName
override suspend fun doWork(): Result {
Log.d(TAG, "doWork")
a1()
return Result.success()
}
suspend fun a1(){
Log.d(TAG, "a1")
for(i in 0..10){
Log.d(TAG, i.toString())
delay(1000)
}
}
}
A2
class MyWorker_A_2 (appContext : Context, workerParams: WorkerParameters) : CoroutineWorker(appContext,workerParams){
private val TAG = MyWorker_A_2::class.java.simpleName
override suspend fun doWork(): Result {
Log.d(TAG, "doWork")
a2()
return Result.success()
}
suspend fun a2(){
for(i in 0..10){
Log.d(TAG, i.toString())
delay(1000)
}
}
}
B1
class MyWorker_B_1(appContext : Context, workerParams: WorkerParameters) : CoroutineWorker(appContext,workerParams){
private val TAG = MyWorker_B_1::class.java.simpleName
override suspend fun doWork(): Result {
Log.d(TAG, "doWork")
b1()
return Result.success()
}
suspend fun b1(){
for(i in 0..10){
Log.d(TAG, i.toString())
delay(1000)
}
}
}
결과는 아래와 같이 나옵니다
- 참조
https://jeongupark-study-house.tistory.com/36
'Android(Kotlin)' 카테고리의 다른 글
기존 Retrofit Callback 계속 붙이면? (0) | 2022.04.13 |
---|---|
Android PeriodicWorkRequest Memo (0) | 2022.04.07 |
Android Log가 안뜰 때 (0) | 2022.03.18 |
RecyclerView Example (0) | 2022.03.09 |
Android Notification (0) | 2022.03.06 |