How to show a view for 3 seconds, and then hide it?

Spawn a separate thread that sleeps for 3 seconds then call runOnUiThread to hide the view.

    Thread thread = new Thread() {
        @Override
        public void run() {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
            }

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    // Do some stuff
                }
            });
        }
    };
    thread.start(); //start the thread

There is an easier way to do it: use View.postDelayed(runnable, delay)

View view = yourView;
view.postDelayed(new Runnable() {
        public void run() {
            view.setVisibility(View.GONE);
        }
    }, 3000);

It's not very precise: may be hidden in 3.5 or 3.2 seconds, because it posts into the ui thread's message queue.

Use post() or runOnUiThread() just something as setTimeout().