Dublo Quo Dublo Quo - 1 month ago 6x
Android Question

Android app takes lot of time to start

I've an Android app. In the

method of splash screen I've add

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
Log.i(SplashActivity.APP_NAME, "Executing post-delayed code");
, 100);

So, what I expect is that this code will get executed after 100ms after onCreate is exited.

But I can see that my app is taking 3 seconds after onCreate() to execute the post-delayed code (also UI appears after 3seconds):

08-30 19:00:45.614 4559-4559/com.example.my I/My Example: OnCreate is exited
08-30 19:00:45.621 4559-4683/com.example.my D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
08-30 19:00:45.654 4559-4683/com.example.my I/Adreno: QUALCOMM build : 166ada0, Ifd751822f5
Build Date : 01/26/16
OpenGL ES Shader Compiler Version: XE031.06.00.05
Local Branch : AU12_SBA
Remote Branch :
Remote Branch :
Reconstruct Branch :

**08-30 19:00:45.662** 4559-4683/com.example.my I/OpenGLRenderer: Initialized EGL, version 1.4

**08-30 19:00:48.646** 4559-4559/com.example.my I/My Example: Executing post-delayed code

Can someone please tell me why an app can take 3 seconds after onCreate() to execute post-delayed code and UI to start appearing?

Please suggest me tips on how I can optimize this time?

One more question, does handler.postDelayed() execute after onStart() / UI is shown?


Consider to add little larger timeout because even default android studio template set timeout time to 300 ms. You can see the comment int android fullscreen application template

 * Some older devices needs a small delay between UI widget updates
 * and a change of the status and navigation bar.
private static final int UI_ANIMATION_DELAY = 300;

Also much depends on your layout because Android draws it in main thread and if your UI have much nesting levels or hard drawing code it cal also reduce performance.