Android升级常见问题
2020-11-12 本文已影响0人
农民工Alan
1、AsyncTask替代方案
- @deprecated Use the standard <code>java.util.concurrent</code> or
- <a href="https://developer.android.com/topic/libraries/architecture/coroutines">
- Kotlin concurrency utilities</a> instead.
*/
@Deprecated
public abstract class AsyncTask<Params, Progress, Result> {
【协程替代方案】如下:
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 替代方案
-
@deprecated Use the <a href="{@docRoot}tools/extras/support-library.html">Support Library</a>
*/
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.