-3

I have been writing this code and it is running properly before, but now its giving exception. If there is anything i have to do in Manifest file or anywhere else please help. I want to show a Blank screen with a drawable set behind and after sleep time of 5000 it must transfers the activity.

package com.example.app3;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

    public class Welcome extends Activity {
        TextView tv;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.welcome);
            tv = (TextView)findViewById(R.id.textView1);


            Thread t1 = new Thread(){
                public void run(){
                    try {
                        Thread.sleep(7000);
                        finish();
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }finally{
                        Intent inn = new Intent(Welcome.this,MainActivity.class);
                        startActivity(inn);
                    }
                }

            };
            t1.start();
}
}
Manan Gupta
  • 491
  • 1
  • 7
  • 11
  • Same question has been asked by (seems by you )http://stackoverflow.com/questions/18356783/start-splash-screen-activity/18357081 – Pankaj Kumar Aug 22 '13 at 05:06

2 Answers2

1

If you are handling UI, then you need a Handler to do so. Consider the below example where the UI (progress bar) is updated using the Handler in a thread.

mHandler = new Handler();

new Thread(new Runnable(
  @Override
  public void run () {
    // Perform long-running task here
    // (like audio buffering).
    // you may want to update some progress
    // bar every second, so use handler:
    mHandler.post(new Runnable() {
     @Override
     public void run () {
       // make operation on UI - on example
       // on progress bar.
     }
    });
  }
)).start();

Hope this helps.

Zax
  • 2,870
  • 7
  • 52
  • 76
0

You can use countdown timer class

new CountDownTimer(2500, 1000) {

            @Override
            public void onTick(long millisUntilFinished) {

            }

            @Override
            public void onFinish() {

                Intent i = new Intent(StartSplashActivity.this,NextActivity.class);
                startActivity(i);
                StartSplashActivity.this.finish();

            }
        }.start();
Hemantvc
  • 2,111
  • 3
  • 30
  • 42