0

I have my MainActivity inside which I have BottomNavigation which loads fragment with the following method

private boolean loadFragment(Fragment fragment) {
        //switching fragment
        if (fragment != null) {
            getSupportFragmentManager()
                    .beginTransaction()
                    .replace(R.id.fragment_container, fragment)
                    .commit();
            return true;
        }
        return false;
    }

When I switch between them quickly my app crashes at various places, but when I go slowly one by one everything works fine

This is how my app structure looks like

enter image description here

I am using Reteofit for API call

I already tried setuserVisibleHint also check if my view rootView is created or not

yuj
  • 11
  • 4

1 Answers1

0

I was using retrofit to get a response of API then pass it to an adapter but due to fast switch using bottom navigation and fragments then my app crashing because the hideProgressBar() throw NullException. I observed that view is destroyed then widgets don't perform.

So I put check to make sure that view is not null. It fixes my situation. I hope it helps other people who are looking for the same solution.

In Kotlin: view and Java: getView() (In Java)

enter image description here

Shahzad Afridi
  • 2,058
  • 26
  • 24