Android升级常见问题

2020-11-12  本文已影响0人  农民工Alan
1、AsyncTask替代方案

【协程替代方案】如下:

val job = lifecycleScope.launch {
    val data = async(Dispatchers.IO) {
        try {
            //耗时操作
            return@async null
        } finally {
        
        }
    }

    withContext(Dispatchers.Main) {
        val result = data.await()
                result?.apply {
                }
    }
}
2、AsyncTaskLoader 替代方案

*/
public abstract class [AsyncTaskLoader]
This class was deprecated in API level 28.

Use the Support Library android.support.v4.content.AsyncTaskLoader

3、IntentService

This class was deprecated in API level 30.
IntentService is subject to all the background execution limits imposed with Android 8.0 (API level 26). Consider using [WorkManager](https://developer.android.com/reference/androidx/work/WorkManager.html) or [JobIntentService](https://developer.android.com/reference/androidx/core/app/JobIntentService.html), which uses jobs instead of services when running on Android 8.0 or higher.

上一篇下一篇

猜你喜欢

热点阅读