Normally I do this:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//initialize variables, set values from argument bundle, etc
List<SomeObject> list = someIntenseDataLoadingProcess();
adapter = new Adapter(list);
}
@Nullable
@Override
public void onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.some_layout, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(getLinearLayoutManager());
recyclerView.setAdapter(adapter);
return view;
}
(I'm going from memory here but that should capture the gist of it).
However if I wrap the list/adapter initialization in a new Thread call, sometimes the result is empty by the time the view is created, or it throws errors in some cases depending on what's going on.
Do I just have the order wrong or something? Where should I be applying the thread?