1. 程式人生 > >android 實現延遲1秒介面發生跳轉

android 實現延遲1秒介面發生跳轉

屬性中

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; } } }