I have another one question about transfering data from Activity
to Fragment
.
In my activity I have next situation: one part of UI is situated in Activity, and another (more dynamic part) is situated in Fragment.
The data which I need to populate my UI elements in Activity and Fragment is on server. To get that data, I am sending request to
server in Acvitity's onCreate()
method. In Activity's callback method: void onDataLoaded(List<MyObject> dataList)
I get data from server.
And in this method I am creating my Fragment and setup data to it. I am passing data to it through the Bundle
object duding creation. Everything
is ok with this. But the issue is in next: on network reconnect I need to load data from server to be sure that all data is up to date. And of course I
need to reinitialize data in Activity and Fragment. But I don't want to fully RE-CREATE fragment. I want just to setup new data to it's fields.
How can I do that properly? Is it a good way to to keep reference in my Activity to that Fragment and call some public method: myFragment.SetMyCustomData(List<MyObject> dataList)
?
I understand that the best way to load data from server in my fragments onCreate()
method, but I can't split it into two API calls and I need that data in Activity as well.
Thanks.