0

My fragment has the reference to a RelativeLayout mContentLayout.

In onDestroyView() (before navigating to another fragment), I need to remove all views of this mContentLayout.

I know that you should deal with UI stuff only from the UI thread, but considering the layout is not visible anymore, would it make sense to call

mContentLayout.removeAllViews()

from a separate thread, so that the views removal doesn't block the UI thread?

Daniele B
  • 19,801
  • 29
  • 115
  • 173
  • No. Removing all views triggers a layout pass which will trigger a new draw pass. It should be fast though. I removes all views, remeasures, then draws in a single flow. – DeeV Apr 01 '15 at 00:46
  • 1
    What about just calling `removeAllViewsInLayout()` ? https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewGroup.java#L4343 – Daniele B Apr 01 '15 at 01:32
  • That will wait until a layout pass to actually remove the views, but it's the same amount of time in any case. I'm 99% certain that calling any of that calling any of these methods will lead to a crash regardless. – DeeV Apr 01 '15 at 04:37

1 Answers1

0

I always stick with the guideline that if there is a good rule of thumb to stick to it. It was there for a reason.

For this particular case, I would believe that you wouldn't need to use a separate thread to perform this. The UI thread should be able to clear and redraw just fine. DeeV said the same thing in your comments.

Randy
  • 1,400
  • 2
  • 12
  • 30