AsyncTask with screen rotation - onRetainNonConfigurationInstance deprecated

后端 未结 2 981
小鲜肉
小鲜肉 2021-01-12 22:23

I am still trying to find the \"correct\" design pattern when dealing with AsyncTasks and screen rotation. I read this commonsware blog post which links to thi

相关标签:
2条回答
  • 2021-01-12 22:42

    There's nothing inherently wrong with using a deprecated method. If your AsyncTask is THAT critical that you can't cancel it and start it up again if your orientation changes, you should consider using a service.

    0 讨论(0)
  • 2021-01-12 22:47

    It's only deprecated on Honeycomb and above, and it will work just fine on those too. The 'new' way is to use loaders (you can use the compatibility library to get those in pre-HC versions) or retained fragments. If you call setRetainInstance() the instance passed as is to the newly created activity (they actually use onRetainNonConfigurationInstance in the FragmentActivity of the compatibility library), so it's effectively the same as what you have now.

    0 讨论(0)
提交回复
热议问题