美文网首页
Android升级常见问题

Android升级常见问题

作者: 农民工Alan | 来源:发表于2020-11-12 21:04 被阅读0次
    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 替代方案

    */
    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.

    相关文章

      网友评论

          本文标题:Android升级常见问题

          本文链接:https://www.haomeiwen.com/subject/fufmbktx.html