android 实现延迟1秒界面发生跳转

来源:互联网 发布:chrome mac版 编辑:程序博客网 时间:2024/06/05 03:55

属性中

private Handler mHandler = new Handler() {        @Override        public void handleMessage(Message msg) {            super.handleMessage(msg);            switch (msg.what) {                case 1:                    Intent intent = new Intent(IntroduceActivity.this, MainActivity.class);                    startActivity(intent);                    break;                default:                    break;            }        }    };

onCreate()

 mHandler.sendEmptyMessageDelayed(1, 3000);

All

public class IntroduceActivity extends Activity implements View.OnClickListener{    private TextView mTvGoClasstime;    private TextView mTvBackClasstime;    private TextView mTvClassName;    private TextView mTvTeacher;    private Button mBtGo;    private Handler mHandler = new Handler() {        @Override        public void handleMessage(Message msg) {            super.handleMessage(msg);            switch (msg.what) {                case 1:                    Intent intent = new Intent(IntroduceActivity.this, MainActivity.class);                    startActivity(intent);                    break;                default:                    break;            }        }    };    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        this.requestWindowFeature(Window.FEATURE_NO_TITLE);        setContentView(R.layout.activity_introduce);        inits();    }    private void inits() {        mTvGoClasstime = (TextView) findViewById(R.id.tv_go_classtime);        mTvBackClasstime = (TextView) findViewById(R.id.tv_back_classtime);        mTvClassName = (TextView) findViewById(R.id.tv_class_name);        mTvTeacher = (TextView) findViewById(R.id.tv_teacher);        mBtGo = (Button) findViewById(R.id.bt_go);        mBtGo.setOnClickListener(this);        mHandler.sendEmptyMessageDelayed(1, 3000);    }    private void delay(int ms){        try {            Thread.currentThread();            Thread.sleep(ms);        } catch (InterruptedException e) {            e.printStackTrace();        }    }    @Override    public void onClick(final View v) {        switch (v.getId()) {            case R.id.bt_go:                break;            default:                break;        }    }}
原创粉丝点击