在开发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实现
方式三(推荐):
SystemClock.sleep();此方法在主线程使用,并且能够忽略中断异常,简洁高效