سؤال

In Adobe AIR there are some useful events such as USER_IDLE and USER_PRESENT to tell if the system is being actively used or is idle after some preset amount of time, BUT they only work for desktop applications (Win / OSX), not for mobile apps (iOS / Android).

So what are the alternatives? Hopefully something that doesn't involve manually resetting a timer on each and every touch event thoughout my app.

Thank you!

هل كانت مفيدة؟

المحلول

Why not manually reset a timer? The USER_IDLE and USER_PRESENT does a very similar job. Yes, faster, but your manual timer won't affect the performance to a degree where it becomes a bottle-neck.

It's simple to make too:

1) Make a library that receives Stage instance as a parameter. Add a few listeners to the stage instance: TOUCH_END, TOUCH_BEGIN and other touches you need. If you want add the menu button listener for Android OS.

2) Make a timer with a long delay (100ms should do). Make a variable - timestamp from last input. A variable with time that defines that user is idle (let's say more then 2000ms). And reset the timer on input. On the tick of the timer check time since last input and write statistics of user activity.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top