26
2017
09

Android延迟界面跳转的方法

在开发IM的时候需要延迟切换fragment,有下面几个方式进行跳转:
方式一:Handler
onClick中:

mHandler.sendEmptyMessageDelayed(0,550);

处理消息

    Handler mHandler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    SplashActivity splashActivity= (SplashActivity)getActivity();
                    splashActivity.ChangeToRegisterFragment();
                break;
            }
        }
    };

很明显就是通过延迟发送Handler来进行调用activity的切换方法

方式二:

        public void go(){  
        Timer time = new Timer();  
        TimerTask timetask = new TimerTask() {  
        Intent intent = new Intent(FirstActivity.this,SecondActivity.class);  
            @Override  
            public void run() {  
            startActivity(intent);  
            finish();  
            }  
        };time.schedule(timetask , 1000);  

    }  

利用TimerTask和Time实现

上一篇:Android Fragment销毁问题 下一篇:19. Remove Nth Node From End of List。