Take the 2-minute tour ×

I want to have a splash screen show up for a few seconds before a dialog pops up. However when I load my app the dialog and the background screen show up at the same time. What can I do to show the background image of my splash.xml before the dialog appears.

Thread waitabit=new Thread(){
public void run(){
}catch(Exception e){



Putting the above before my dialog just makes it dark for 2 seconds before showing everything all at once. Calling my dialog inside of the thread causes and error because we cant put dialogs in a thread.


share|improve this question

4 Answers 4

up vote 1 down vote accepted

Try putting the above code in an AsyncTask so that the UIThread does not sleep.

new AsyncTask<Object, Void, Void>() {

    protected void onPreExecute() {
        // show background image

    protected Void doInBackground(Object... params) {
        new Thread() {
            public void run() {
                try {
                } catch (Exception e) {
        return null;

    protected void onPostExecute(Void result) {
        // open dialog

share|improve this answer
could you explain this a bit more? I don't see where you declared the thread waitabit and when I put it into eclipse I get a compile error. –  Sean Aug 25 '11 at 2:51
Sorry, that was some hasty copying. I've edited it to make more sense. The onPostExecute method runs after the background thread has completed, so you'll want to use that method to trigger the dialog. The onPreExecute method is optional however. You can load the background image before calling execute on the AsyncTask and it shouldn't make a difference. The key thing to understand here is that the onPreExecute and onPostExecute methods run on the UIThread while the background job does not. –  Thomas Williams Aug 25 '11 at 3:08
The same thing is happening where the dialog and background show up at the same time, just two seconds later. What I want is essentially to delay the dialog by a few seconds and to show the background while its loading (or sleeping),or something like that. Thanks –  Sean Aug 25 '11 at 3:23
Ok, I edited again. This time I think it will work. At least it did for me in a similar situation. –  Thomas Williams Aug 25 '11 at 3:33
Got it, thank you so much for your help! –  Sean Aug 25 '11 at 7:26

This link has a pretty good solution on how to show a splash screen and call a handler once the splash screen is finished (i.e. this would allow you to display your dialog box).

share|improve this answer

How about an activity to show the splash screen that, in turn, launches the activity with the dialog?


share|improve this answer
I tried this but it looks like a screen with the background and then it fades away and has the screen with the dialog. Doesn't look right –  Sean Aug 25 '11 at 2:52

Try this in your onResume:

Runnable myRunnable = new Runnable(){
            public void run() {
                // do your dialog
Handler myHandler = new Handler();
long delayMillis = 5000; // 5 seconds
myHandler.postDelayed(myRunnable, delayMillis);
share|improve this answer

Your Answer


