I am working on learning Android. From the documents I have read so far I can’t figure out how to get the splash View to show (during the sleep the screen stays blank). It appears I need to start a new activity for the main layout, but this seems wasteful (the splash should be forever gone, I’d like to reuse its thread).
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class Ext3 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Log.v("Ext3", "starting to sleep");
try {
Thread.sleep (5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.v("Ext3", "done sleeping");
setContentView (R.layout.main);
}
}
I believe your splash screen never gets shown because you never give the UI thread (that you are in) a chance to draw it since you just sleep there doing nothing.
Instead of the Thread.sleep, I would suggest you look into a Timer or something like that to schedule the refresh and changing the content of your view; an alternative would be to start an AsyncTask where you could sleep before changing the view as you are doing now.
Do not sleep or in any other way block the UI thread, that’s bad… (causes ANR)