Hello!

There is a fragment, at the touch of a button on which, AsyncTask launched and starts downloading data from the Internet. At the end of the download, this data is displayed in the RecyclerView this fragment.

As far as I understand, if in the process of AsyncTask operation the configuration of the device changes (for example, the screen orientation), then we will not receive the data from AsyncTask , since the fragment will be created anew.

Actually, the question is: how to be in such situations?

Ps. I read the Internet, there are a lot of ways, but the information is somehow hard to perceive and as a result porridge turns out in my head. Tell me, please, the most correct , from your point of view, method of solving this problem.

Thank!

Pps. It will be cool if someone AsyncTaskLoader an example using AsyncTaskLoader .

  • four
    Here you have a stylish fashionable and youthful way: habrahabr.ru/post/305478 - YuriySPb
  • @Yuriy SPb, thanks for the article! But, unfortunately, I am far from RxJava . Maybe it's time to try :) - s8am

1 answer 1

The most correct way I consider the imposition of work with the network service. The service (properly configured and running) will not die when the configuration changes. And you can display the data obtained in the service on View in any of these ways: Methods of information exchange between Service and Activity