Pantalla de inicio del juego de Android

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 ?

preguntado el 01 de febrero de 12 a las 03:02

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. -

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 -

2 Respuestas

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);

Respondido 01 Feb 12, 07:02

normally, what kinds of things would be loaded when starting the game? - George

I got the error "can't create handler inside thread that has not called looper.prepare()" - George

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. stackoverflow.com/questions/5009816/… - Sameer

puedes comprobar mi respuesta aquí. The way I used AlertDialog, you can use AlertDialog without Buttons for same purpose.

contestado el 23 de mayo de 17 a las 14:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.