in my app I got a thrad that checks every 60s data from a webservice (defined in onCreate()):
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(PERIOD);
if(condition) do_something();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
Additionally i got a handler executing a method after a period of user inactivity:
private Handler disconnectHandler = new Handler();
private Runnable disconnectCallback = new Runnable() {
@Override
public void run() {
do_something_else();
}
};
public void resetDisconnectTimer(){
disconnectHandler.removeCallbacks(disconnectCallback);
disconnectHandler.postDelayed(disconnectCallback, TIMEOUT);
}
@Override
public void onUserInteraction() {
super.onUserInteraction();
resetDisconnectTimer();
}
Now I got the problem that onUserInteraction() is called after PERIOD too and not only after TIMEOUT. Any ideas to get both working?
Thanks in advance.
may be you want read the source below:
Instrumentation.java
public void callActivityOnUserLeaving(Activity activity) {
activity.performUserLeaving();}
Activity.java
final void performUserLeaving() {
onUserInteraction();
onUserLeaveHint();}
public boolean dispatchKeyEvent(KeyEvent event) {
onUserInteraction();
...
}
public boolean dispatchKeyShortcutEvent(KeyEvent event) {
onUserInteraction();
.....
}
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
onUserInteraction();
}
....
}
public boolean dispatchTrackballEvent(MotionEvent ev) {
onUserInteraction();
....
}
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
onUserInteraction();
....
}
onUserInteraction() be called as below: