(1)获取到相关数据后跳转前定时跳转
///totaltime总共定时时间(单位:毫秒)
///celltime 间隔时间(单位:毫秒)
new CountDownTimer(totaltime, celltime) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
//定时完成后你需要做的事情
Intent intent = new Intent(StartActivity.this,MainActivity.class);
startActivity(intent);
finish();
}
}.start();
(2)跳转时间 = 定时总时间 - 获取相关数据所花费时间
///sleepTime 定时总时间
///costTime 获取数据花费的时间
new Thread(new Runnable() {
public void run() {
long start = System.currentTimeMillis();
//你所需做的服务器请求等
......
long costTime = System.currentTimeMillis() - start;
//等待sleeptime时长
if (sleepTime - costTime > 0) {
try {
Thread.sleep(sleepTime - costTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//定时完成后你需要做的事情
Intent intent = new Intent(StartActivity.this,MainActivity.class);
startActivity(intent);
finish();
}).start();