现在我正在开发一个应用程序,一旦应用程序闲置一段时间就需要退出。每当触摸屏或触控板或键盘没有输入时,应用程序必须突然关闭
任何人都可以帮我解决源代码吗?
答案 0 :(得分:0)
将SystemListener2实现到您的UiApplication
public class ClassName extends UiApplication实现SystemListener2
其中一个实现的方法“backlightStateChange(boolean on)”
public boolean check;
public void backlightStateChange(boolean on) {
check = true;
if (on == false) { //on idle
long idlestart = System.currentTimeMillis();
long endtime = idlestart + 50000; //5mins wait to exit
while (check) {
if (endtime < System.currentTimeMillis()) {
System.exit(0);
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
}
} else {
check = false;
}
}