CountDownTimer倒计时:
函数:
cancel() 取消当前任务
onFinish() 当前任务完成的时候调用
onTick(long millisUntilFinished) 当前任务每完成一次倒计时间隔时间时回调
start() 开始当前的任务
参数:
参数 - millisInFuture:设置倒计时的总时间(毫秒)
参数 - countDownInterval:设置每次减去的时间(毫秒)
new CountDownTimer(60 * 1000, 2000) {
@Override
public void onTick(long millisUntilFinished) {
//当前任务每完成一次倒计时间隔回调
if (queryRichPay(orderNo, orderType)) {
dismissLoading();
paySuccess(result.get("transactionId").toString());
this.cancel();
}
}
@Override
public void onFinish() {
//执行完成
dismissLoading();
payError("用户超时未支付,订单交易取消");
}
}.start();
Timer延迟发送:
// 延迟2s再发送
Timer timer = new Timer();
timer.schedule(new TimerTask() {
public void run() {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
intent.setData(uri);
startActivityForResult(intent, 0x006);
this.cancel();
}
}, 2000);// 这里是毫秒