5 ways to improve app start up time

As you probably know the speed your app takes to start up is important. Here are 5 ways you can do to mitigate slow start up speeds.

Use StrictMode to find long running tasks on the UI thread

At times, things are overlooked, for example, doing IO operations on the main thread. Remember on older devices that have slow IO speeds this may have much larger performance issues than on newer faster devices.

//in the class that extends Application
public void onCreate() {
if (DEVELOPER_MODE) {
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.build());
}
 }

Check Logcat for any StrictMode warnings.

Lazy load

Only initialize what you absolutely need at start-up. Lazily load anything that isn’t needed at start up. Use singletons if a class should only be instantiated once.

Things to question: Do I need do to this on start up? If so, do I need to do this on the main thread?

Optimize your layouts

Some views are more expensive than they may first seem. RelativeLayout is one of them — make sure it is low down in your view hierarchy. This is because it has to measure all its children twice instead of once. Again, LinearLayout with layout_weight will also need to measure its children twice. For more ways to optimize layouts, check here.

Use android:windowBackground in your theme

Set the final windowBackground color to emulate a faster activity load time. Remember to avoid overdraw.

Use TraceView to find long running/unneeded work on the UI thread

TraveView is amazingly powerful. It may seem a little confusing to start off with (it did with me!) but it actually is rather simple. This may help you if it’s your first time using it — Android developers TraceView tutorial.


Finally, if you’re testing on 4.4 and above, testing the launch time is even easier. Launch the activity and then check the logcat for ActivityManager log for the amount of time the activity took to load.

ActivityManager: Displayed com.giljulio.example/.LauncherActivity: +553ms

Don’t forget to swipe the app away from recents when testing to simulate a cold start.