I've read a few posts on the topic, . Here is my strategy; I have a drawing app that shows the user-created drawings in a ListView. Once the user selects a drawing, the DrawingEdit Activity is fired up, with the drawing being loaded in onCreate, roughly as follows:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set the layout for the activity
setContentView(R.layout.drawing_view);
// do potentially expensive loading of drawing here
loadDrawing();
}
Where loadDrawing()
is loading the individual shapes of the user's drawing from a database. Now, for 95% of the drawings, and for the 'typical' use case, this works fine, as the Activity loads quickly with little to no delay. However, for very very complex drawings, the delay can be up to two seconds. To help resolve this issue, I've tried an AsyncTask, which works great for the 5% of drawings that are excessively large, but for the other 95% seems like overkill, and actually makes the loading a little slower due to having to fire up the AsyncTask. It's not the worst solution, but I'm looking at alternatives.
Now, in addition to the drawing data that I have stored in the database, I also have a static PNG version of the drawing that I can make use of... so the solution that I'd like to use is along the lines of:
- Load a temporary 'splash' screen view at the beginning of onCreate(), using the static drawing as a placeholder that the user can immediately review while the drawing is loading.
- Start the sometimes expensive
loadDrawing()
routine. - Upon completion switch the View and show the secondary view with the fully interactive drawing canvas that includes the shapes from
loadDrawing()
.
My problem is that if I model the above solution roughly as below, the 'splash' layout is never displayed, and there is still the same delay until loadDrawing()
is complete and then the final layout is displayed. Any info on what is happening here? Should I move the loadDrawing()
to onResume so that the initial splash UI has a chance to load before loadDrawing()
is triggered?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set the layout for the activity
setContentView(R.layout.splash_view);
// do potentially expensive loading of drawing here
if (loadDrawing()) {
// set the layout for the activity
setContentView(R.layout.drawing_view);
}
}