1

I have two fragments A & B.
I have switched to B from A using following code :

    FragmentManager fragmentManager;
    FragmentTransaction transaction;
    fragmentManager = getActivity().getFragmentManager();
    transaction = fragmentManager.beginTransaction();
    transaction.setCustomAnimations(R.animator.enter_anim, R.animator.exit_anim,R.animator.popenter, R.animator.popexit);
    transaction.replace(R.id.fragmentLayout, new B())
            .addToBackStack("tag").commit();

B contains SQLite operations(SugarORM).
While switching from A to B, the screen freezes, even if I am using AsyncTask & IntentService for db operations.
Also, when I press back button [getFragmentManager().popBackStack();], the screen freezes for couple of seconds, before it switches back to A from B.
The popBackStack animation is too not visible.
I tried showing indeterminate progress bar & animation-list in imageview, but they freeze too & it looks as if they are static images.

Pranav Karnik
  • 3,318
  • 3
  • 35
  • 47
  • 1
    check if your FRAGMENT A has any ui blocking calls in onCreateView/onViewCreated. – Nishant Pardamwar Aug 30 '16 at 10:02
  • post your AsyncTask. and you can see animation by increasing delay . – Zar E Ahmer Aug 30 '16 at 10:09
  • put logs in all your methods in both fragments and you can find out by checking logs during which two process(between which 2 logs) so long time is taken and you can rectify the reason.(specially in onResume or in onPause)If possible paste the code. – Mansi Salvi Aug 30 '16 at 10:09

1 Answers1

1

Check out this article on profiling your main thread: https://developer.android.com/studio/profile/traceview.html

This will show you what's hogging the main thread, which is probably the reason for the freeze.

Also, follow @NishantPardamwar's advice for checking the fragment's lifecycle methods, which run on the main thread and are likely culprits.

orip
  • 73,323
  • 21
  • 116
  • 148