定义android系统睡眠时间间隔

时间:2011-12-26 08:34:38

标签: android

我正在编写一个应用程序,如果用户在一段时间内没有与手机交互,应该会在屏幕上显示。 (我打算写一个服务,在此之后显示一项活动)

编辑:活动可能没有打开(这就是我必须在服务中定义非交互时间的原因)

1 个答案:

答案 0 :(得分:0)

是的,Activity类中有这个很棒的方法onUserInteraction()。 您可以将当前时间作为长整型存储在变量中并显示时差。

onUserInteraction(){
  latestInteractedTime = System.currentTimeMillis();
}

// In some method you want to probably display the time difference
String diff = "Time diff: " + (System.currentTimeMillis() - latestInteractedTime);
textView.setText(diff);