3

I've been working for several months in an app. The version uploaded to the playstore works fine. Recently, doing some improvements, the whole app has started to work in a very strange way.

If you swith between fragments, after a while it does not inflate properly the fragments, putting always the content of the first one. So, if you switch the fragment, the action bar changes but the content is always the same (and you cannot interact with it).

Here is a quick video of the error https://streamable.com/9exa

I am going crazy as there is no log or trace whatsoever.

I am using the usual way of swithing fragments and the most intriguing part is that at the beginning everything works ok:

Fragment fragment = getSelectedFragment(index); // returns the desired fragment
FragmentManager fragmentManager = getFragmentManager();

//Pop backstack
for(int i = 0; i < fragmentManager.getBackStackEntryCount(); ++i) {
    fragmentManager.popBackStack();
}

fragmentManager.beginTransaction()
               .replace(R.id.container, fragment)
               .addToBackStack(null)
               .commit();

Do anyone has any kind of idea what could be happening here? Thanks!

edit: I also have tried to clear the backstack in case it was the problem, but it doesn't change anything

solved: As I explain in my answer, I have discovered that is a problem related to a SwipeRefreshLayout. More information about this problem can be found at When switch fragment with SwipeRefreshLayout during refreshing, fragment freezes but actually still work

Community
  • 1
  • 1
Adrian Latorre
  • 161
  • 2
  • 10

3 Answers3

3

Ok, I found out the problem.

It seems that a SwipeRefreshLayout was the one causing all the problems. One of my fragments was using it, and after switching fragments a couple of times it gets stuck.

Removing it, or disabling it setEnabled(false) solves all the problems.

I hope it will help to anyone that is having the same problem!

Another thread in SO that refers to the same problem: When switch fragment with SwipeRefreshLayout during refreshing, fragment freezes but actually still work

Community
  • 1
  • 1
Adrian Latorre
  • 161
  • 2
  • 10
0

What fragments are you using?

I had some strange behaviour using framework fragments, and i switched to V4 and everything worked fine

alorma
  • 924
  • 8
  • 10
0

Please check this link: FragmentManager popBackStack doesn't remove fragment

I am using the following code in my activity for switching between fragments and it is working fine. My app's minSdkVersion is 15.

    private void setFragment(Fragment fragment) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction =
            fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.container, fragment);
        fragmentTransaction.commit();
    }
Community
  • 1
  • 1
shivam gupta
  • 141
  • 1
  • 6