我正在Android中做应用程序,我想在我的应用程序中添加这个未来。等待十秒钟,如果有人不触摸屏幕重新启动到android中的应用程序,我该怎么做?
-
启动计时器以增加时间,如果达到 10 秒,则根据需要执行任务
timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { public void run() { if(userInteractionTimeout==10) { // Do your task } userInteractionTimeout++; } }, 0,1000);
-
覆盖活动中的用户交互() - 重置计时器
@Override public void onUserInteraction() { // TODO Auto-generated method stub super.onUserInteraction(); userInteractionTimeout=0; Log.d(LOG_TAG,"User Interaction : "+userInteractionTimeout); }