-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();
}
}
4

2 回答 2

1

如果您正在处理 UI,那么您需Handler要这样做。考虑以下示例,其中 UI(进度条)使用线程中的 Handler 进行更新。

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

希望这可以帮助。

于 2013-08-19T04:58:34.730 回答
0

您可以使用倒数计时器类

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();
于 2013-08-22T03:33:02.733 回答