tags:

views:

57

answers:

2

Hi All,

My question is suppose i have to views(Screen). when i open my application from the emulator first screen should stay for just 5 secs and automatically new screen should appear(2nd). i Know i can do this through timer concept but dnt know hwto do that in android? So pls help me in this problem.

+1  A: 

I completely agree with EboMike about not showing a splash screen. It's a bad practice with any app (desktop or android) and often just covers up sloppy programming. Get the user to do useful work as soon as possible and do any other startup work asynchronously.

However, sometimes lawyers are in charge of software, sometimes it's a marketing person, and sometime you just can't defer long startup code. In this case, you need an answer. The simplest is to have your main activity be your splash scree. In the splash screen activity, create a handler to start your real main activity doing something like this:

       Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            startActivity(...);
            finish();
        }
    };

     handler.sendEmptyMessageDelayed(0, 5000);
dhaag23
A: 

One way to do that in Android is to use android.os.Handler class. It is rather simple:

  • create new Handler() object e.g.

    mTimeoutHandler = new Handler();

  • initiate delayed execution with

    mTimeoutHandler.postDelayed(myRunnable, 5000);

  • define runnable myRunnable that will execute when timeout expires

Desiderio