0

In some games, the game startup is to display the company name for a moment and then display the main menu for starting the game.

I would like to do something similar. But I am not sure if my way is a good way...

In my plan, I would display the startup image and then make the program sleeps for 1 seconds and then display the main menu

Shall I use the sleep function to hold the screen for a second?

If I want to use flash image instead of static image? Is it also feasible? What's the usual way to do something like this ?

Lucifer
  • 29,392
  • 25
  • 90
  • 143
George
  • 13
  • 3
  • normally people do that because they are loading sth. you might want display the image, put the loading in background, and bring it up when its done. – lynnyilu Feb 01 '12 at 03:43
  • For that you may use UI thread, and display your static screen for few second. This task may be perform by Thread or Async task – Andy Feb 01 '12 at 03:47

2 Answers2

0

you can check my answer here. The way I used AlertDialog, you can use AlertDialog without Buttons for same purpose.

Community
  • 1
  • 1
Lucifer
  • 29,392
  • 25
  • 90
  • 143
0

You should not sleep the UI thread. Use AsyncTask instead. e.g.

    setContentView(<company name screen>)
    new AsyncTask<Object, Object, Object>() {
        protected Object doInBackground(Object... params) {
            try {
                // If you have nothing to do just sleep
                Thread.sleep(<time duration>);
            } catch (InterruptedException e) {
                // handle this
            }
            return (Object)null;
        }

        protected void onPostExecute(Object result) {
            // This runs on UI thread
            setContentView(<your next screen>)
        }
    }.execute((Object) null);
Sameer
  • 4,379
  • 1
  • 23
  • 23
  • normally, what kinds of things would be loaded when starting the game? – George Feb 01 '12 at 15:55
  • I got the error "can't create handler inside thread that has not called looper.prepare()" – George Feb 02 '12 at 13:17
  • Looking at some another thread on this error it seems like you may be calling AsyncTask for a non-UI thread. That is not allowed. http://stackoverflow.com/questions/5009816/android-cant-create-handler-inside-thread-that-has-not-called-looper-prepare – Sameer Feb 02 '12 at 17:51