I am using the a ViewStack controlled with visibility of selected NavigatorContent being dependent on user selection of an option from a drop down menu.
Each View of the ViewStack has its own separate UI elements including 2-3 DataGrid, charts etc - think of it as a simple school application where each view binds to a course and shows performance of students for that course (while listing students in grid)
Sometimes, there is a problem with showing the data though - before the Rendering completes, the data is ready to be populated; this throws a null exception as the UI element where the data needs to be populated has not been created yet.
For this, I made the 'creationPolicy' set to 'all'. All works just fine after this property is set. But there certainly are tonnes of performance issues:-
- Even if the user never ever visits beyond the 1st visible view, the other views do get rendered (UI elements initialized and created).
- Performance hit at startup - startup time is large and grows with the number of views I have (right now I have 9 views with creationPolicy set to all)!! Application was quick to load when only the 1st view was visible by default and creationPolicy was set to default/auto
- UI kind of hangs/becomes unresponsive while application starts (as it all happens in the same thread)
What could be a possible solution to this.
These are the solutions that I had in mind, and which didn't work for a reason or two:-
- For the first time a view is selected via the dropdown controller (i.e. when the rendering cum UI creation is yet to take place), I can show a preloader or sometime. I tried doing this, but the UI still hangs/becomes unresponsive.
- CallLater can it help? Not really, as I would still be creating all views even if they are not required.
So, I need an elegant way of displaying the views (and show some sort of progress or loader) when they are created/instantiated.
Update
I get the Null errors when there is a sort of race condition - when the processing (which returns data to be filled into UI components, lets say a grid) completes before the rendering of the UI element completes - I have recognized why it happens. Initially, I had creationPolicy set to default, so whenever I use to select a view, it was created at that time; and in case the data to be populated was returned before the elements of the view were created there were null pointer (as the UI element I use to refer to were still be created and thus were null at that instance). Now I am being forced to set the creationPolicy to all so that UI is created for all views and I fire the data processing on selection of that view from the dropdown.
What I'd rather like to do is to have a way to create the UI on demand (and not all of the UI even if it is not being used).