I’ve written an app which processes a lot of data on startup; first startup time of the app is rather slow, but so are subsequent launches.
I previously thought that the relatively un-responsive startup times (~7 seconds) were due to data processing on first load – a bit of debugging suggested about 2 seconds to cold-load. So I redesigned my data structures so they’re easier to serialize to persistent storage in between launches (so it caches stuff) and it now saves state when the app finishes in about 20ms, and loading time is about 10-20ms. Much better. (p.s. it’s not using the built-in Java serialization, as the state files are now so simple it’s easier to save in a plain, human-readable (and editable) text file – it’s still pretty quick at reloading from this though!)
However, I’m still finding that the app startup time is about 5 seconds – I’ve looked in aLogCat which has an entry:
I/ActivityManager(...) blah blah blah: +5s193ms
So more than 5 seconds to load a relatively simple layout (a few nested LinearLayouts, and a few TextViews – nothing special, and no images) – admittedly that time goes down with subsequent launches (I close the app and open it again, it’s ~700ms; rinse and repeat for similar results).
Soooo my question is: how can I improve the app loading times? I’m happy that first load takes a little while to process everything – that’s fine. But is there a way I can keep the thing in memory, or at least get it into a restorable state so whatever ActivityManager is doing doesn’t take so long? I’d like it to be something I can open (probably bound to long-hold search or similar), do whatever, and close it again – thus it needs to open quickly!
Thanks in advance 🙂
Seb
Run your heavy-duty start-up work in a background thread that you launch in
onCreate. (An AsyncTask is good for this.) Design your UI to show something meaningful (at least an indeterminate progress bar) when there is no data. When the data is loaded, post a Runnable (or implementonPostExecutein your AsyncTask) to update the UI to the real thing.