0

I would like to show progress dialog while my fragment is loading. I am converting the size of some images in the fragment, so preparing the fragment takes some time. But after I show the progress dialog, it doesn't spin, it just stuck until fragment is getting ready.

Here is my example codes. Code for creating fragment:

//show progress bar
setProgressBarIndeterminateVisibility(true);
//Create fragment
MyFragment myFragment = new MyFragment();
setFragment(myFragment).commit();

In my fragment code:

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setProgressBarIndeterminateVisibility(false);
}
MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
cagryInside
  • 790
  • 2
  • 15
  • 41

1 Answers1

1

Whenever the app "freezes" or gets stuck, this is because you are performing a long-running operation, such as reducing image sizes, on the main or UI thread. In order to prevent this, perform any long-running operations on a separate thread with AsyncTask. An example of this can be shown here.

Community
  • 1
  • 1
AggieDev
  • 5,015
  • 9
  • 26
  • 48