You are blocking the UI thread, which is a big no-no. The system cannot draw the screen until the onCreate method onCreate . The usual way to do what you want is to start a separate thread that waits, and then sends Runnable to the UI thread:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.logo); final Handler handler = new Handler(); final Runnable doNextActivity = new Runnable() { @Override public void run() {
A slightly simpler way (as Athmos suggested in his answer) is to let the handler do the countdown for you:
Handler mHandler; Runnable mNextActivityCallback; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.logo); mHandler = new Handler(); mNextActivityCallback = new Runnable() { @Override public void run() {
This has the advantage that you can undo the transition to the next action (if, say, use presses the back button or if you find an error condition or something during these 2 seconds):
@Override protected void onPause() { if (isFinishing()) { mHandler.removeCallbacks(mNextActivityCallback); } }
source share