1. 线程
new Thread(new Runnable() {
public void run() {
//sleep设置的是时长
Thread.sleep(1000);
handler.sendMessage();
}
}).start
2. 延时器
TimerTask task = new TimerTask() {
@Override
public void run() {
MotionEvent event = MotionEvent.obtain(195534905, 195534905, MotionEvent.ACTION_DOWN, 549, 867, 0);
webView.onTouchEvent(event);
}
};
Timer timer = new Timer();
timer.schedule(task, 3000);
3. Android消息处理, 推荐使用这种方式
new Handler().postDelayed(new Runnable()) {
public void run() {
//要执行的任务
}
}, delay);
参考链接:https://www.jianshu.com/p/a2689e38048b
网友评论