当设备空闲时,如何得到用户活动通知?

Overview
How to get a notification of user activity when the device has been idle?


Description
How to implement a mechanism that gives an application a notification of user activity when the device has been idle?


Solution
Write an "Activity Manager" CTimer that monitors InactivityTime. When the CTimer launches, do
TTimeIntervalSeconds inactiveTime = User::InactivityTime();
if (inactiveTime < KMyActivityManagerTimerInterval)
    {
    CTimer::Cancel();
    NotifyApplicationOfUserActivityL();
    }


Summary
You can implement an "Activity Manager" by using CTimer. When the timer launches, compare the timer interval to Inactivity Time. If the Inactivity Time is smaller than the timer interval, you know that there has been activity while the timer was counting.

 

==========================================================

自己做一个timer来判断是否待机,不会特别准,但也可以达到一定的效果。

if (inactiveTime < KMyActivityManagerTimerInterval)
改为if (inactiveTime > KMyActivityManagerTimerInterval)

就说明一段时间内(KMyActivityManagerTimerInterval)用户已经没有任何活动了。

你可能感兴趣的:(当设备空闲时,如何得到用户活动通知?)