Reputation: 577
I have an asynctask in my fragment.Whenever i get in this fragment it loads all the data from the beginning but it's waste for me.So i want that it loads only one time.How can i fix this?
Upvotes: 2
Views: 7143
Reputation: 577
Where in your code do you wish to load your initial data? Do you initially load it from parent activity? Wherever that is, that's where you need to implement your AsyncTask and maintain list of items. not within Fragment. From there, you simply need to do the following in your fragment:
public class Android extends Fragment{
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
/** Grab your initial data **/
setListAdapter(new ArrayAdapter<String>(context, layout, <your data>);
}
}
Upvotes: 0