I have an Activity with this structure:
FrameLayout
ProgressBar
ViewStub
The ViewStub inflates a Fragment in a separate thread. What I need is to display the progress while the fragment loads. The problem is the ProgressBar is not spinning while the stub inflates (in my case about half a second: it's a heavy fragment) I've tried everything: showing/hiding the view, invalidate, show them in ViewSwitchers...etc, nothing works, as soon as the ViewStub inflates, it starts spinning, it's like the ui is frozen while it inflates but doing it in another thread doesn't seem to improve. What should I do?
ViewStub
on a background thread? – Vivepost()
) clearly says The runnable will be run on the user interface thread so you aren't doing anything on another background thread. Second of all you shouldn't instantiate views on a background thread because they create stuff like handlers which may be tied to the wrong thread(instead of the UI thread). Keep in mind that all of the fragment's callbacks will be run when you inflate theViewStub
containing the embedded fragment, also make sure that if you load heavy data in theinitFragment()
method you actually use a background thread. – Vive