During loading of my android application i want to show a logo during the first 2,3 seconds of launching, I think it’s less ugly than just seeing a UI after launching.
So in my code i make first a setContentView with the logo (splash) and after a setContentView with the UI (main).
The pb is instead of seeing the logo screen I just see a black screen.
I am doing that in main thread so I don’t understand.
Do you have an explanation of the problem and if possible a workaround ?
The not working well onCreate() of the activity is the following (black screen during 5 seconds and after can see the UI, no exception thrown) :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash); //doesn't work
Log.i(TAG, Thread.currentThread().getName());
//this.r
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
Log.i(TAG, Thread.currentThread().getName() + e.toString() );
}
setContentView(R.layout.main); //work OK
}
}
if I just left the class with the code below there is no problem I can see the “first” and only view :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash); //work OK
}
}
You can use
TimerTaskinstead of usingThread.sleepfor making wait in main UI thread as: