Hi guys i'am here because I've already tried almost everything since running the fragment transaction in Asynctask or in a new thread nothing seems to work and i can't figure out by myself.
What I've tried:
and others
My problem:
- The fragment do some heavy work so i implemented the asynctask inside the
- fragment but i can't update the fragment
- My UI freezes when replacing with the fragment
- I create all my views programmatic
- My fragment returns a views
- I pretend to display a progressbar while the frag is not ready
My main:
Bundle bundle = getIntent().getExtras();
FragmentTransaction fragmentTransaction = getFragmentManager()
.beginTransaction();
FragTopics insideTopicsFrag = new FragTopics();
insideTopicsFrag.setArguments(bundle);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.replace(R.id.mainFragment, insideTopicsFrag);
fragmentTransaction.commit();
My fragment: the createTopics returns a View with all the content, in another words it's the view that in the past was return in the onCreateView.
public class FragTopics extends Fragment {
View v;
public FragTopics() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
v = new View(getActivity());
new TopicsAsyncTask().execute();
return v;
}
private class TopicsAsyncTask extends AsyncTask<Void, Void, Boolean> {
ManSession session;
String courseId;
Long topicId;
String courseName;
MoodleCourseContent[] courseTopics;
MoodleCourseContent singleTopic;
private final ProgressDialog dialog = new ProgressDialog(getActivity());
@Override
protected void onPreExecute() {
this.dialog.setMessage("loading...");
this.dialog.show();
}
@Override
protected Boolean doInBackground(Void... params) {
ObtainData();
return true;
}
@Override
protected void onPostExecute(Boolean result) {
this.dialog.dismiss();
// The createTopics returns the View with all contents
v = createTopics(singleTopic, courseName, courseId, topicId);
}
}