I'm facing problem with replacing fragment using FragmentManager. My problem is freezing the UI. I'm trying to find some good practices and/or library to handle my problems.
Part of my code:
Main activity layout:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.DrawerLayout>
Main activity class
public class MyActivity extends Activity
with method
public void nextFragment(Fragment fragment, int position) {
fragment.setArguments(new Bundle());
FragmentManager fragmentManager = getFragmentManager();
fragmentManager
.beginTransaction()
.replace(R.id.content, fragment).commit();
}
Each of my fragment is like
import android.app.Fragment;
public class SomeFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
RelativeLayout rootView = (RelativeLayout) inflater.inflate(
R.layout.fragment_layout, container, false);
//many long time data downloading & creating view
}
private void nextFragment() {
((MyActivity) getActivity()).nextFragment(
new SomeNextFragment(), 0);
}
}
Now because of downloading data on each fragment start my UI is freezing. Thanks in advance for any help.