活动类字段:
private static final int KEY_TIMEOUT = 60000;
private long lastKeyEventTime;
private boolean checkKey;
在活动.onCreate() :
checkKey = true;
Thread t = new Thread(){
while (checkKey){
if (lastKeyEventTime!=0 && System.currentTimeMillis()-lastKeyEventTime>TIMEOUT){
// TIMEOUT
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
t.start();
在活动.onDestroy():
checkKey = false;
lastKeyEventTime = System.currentTimeMillis();