2

I am working on android application .There are 4 tab on Home screen . there are multiple fragment under each tab.I am moving from fragment to second fragment and back on first fragment . when i again moves on second fragment . it does not show any data which i am fetching from web service.It is showing on progress dialog.what may reasons .

I am switching fragment like this.

            FragmentManager fm = getFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();

            FragmentName llf = new FragmentName();

            ft.replace(R.id.container_framelayout, llf);
            ft.addToBackStack(null);
            ft.commit();

1 Answers1

0

I don't know if it's related to your problem but when you create a fragment from the same class multiple times, you shouldn't do FragmentName llf = new FragmentName();

You should do something like that :

FragmentName llf = FragmentName.newInstance();

And in FragmentName.class :

public static FragmentName newInstance(){
    return new FragmentName();
}

This way, a new Fragment will be made and you won't have any duplicated or "shared" fragment. More information are available here : Best practice for instantiating a new Android Fragment

Community
  • 1
  • 1
Antoine
  • 583
  • 2
  • 6
  • 21