不可以用onTouchEvent,因为点击空白处没有反应
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
handler.removeCallbacks(runnable);
handler.postDelayed(runnable,5000);
return super.dispatchTouchEvent(ev);
}
private Runnable runnable= () -> {
if(!this.getClass().getName().equals(AdActivity.class.getName())){
startActivity(new Intent(MyBaseActivity.this, AdActivity.class));
}
};
@Override
protected void onResume() {
super.onResume();
handler.postDelayed(runnable,5000);
}
@Override
protected void onDestroy() {
super.onDestroy();
handler.removeCallbacksAndMessages(null);
}
@Override
protected void onStop() {
super.onStop();
handler.removeCallbacks(runnable);
}
多少秒内没有操作手机就跳转广告页
最新推荐文章于 2022-11-23 11:30:47 发布