mobile 在长时间没有操作的时候进入待机状态:
进入待机状态之后,所有进程都进入停止状态,调用电源管理可以解决这个问题:
If you want your program to not be put to sleep while it's running, the best way is to create a KeepAlive type function that calls SystemIdleTimerReset, SHIdleTimerReset and simulates a key touch. Then you need to call it a lot, basically everywhere.
{
WINAPI ();
};
()
{
DWORD = ;
DWORD = ();
(( - ) > || < )
{
();
();
keybd_event(VK_LBUTTON, , KEYEVENTF_SILENT, );
keybd_event(VK_LBUTTON, , KEYEVENTF_KEYUP | KEYEVENTF_SILENT, );
= ;
}
}
This method only works when the user starts the application manually.
If your application is started by a notification (i.e. while the device is suspended), then you need to do more or else your application will be suspended after a very short period of time until the user powers the device out of suspended mode. To handle this you need to put the device into unattended power mode.
(!:: (PPN_UNATTENDEDMODE, TRUE))
{
}
(!:: (PPN_UNATTENDEDMODE, FALSE))
{
}
During unattended mode use, you still need to call the KeepAlive a lot, you can use a separate thread that sleeps for x milliseconds and calls the keep alive funcation.
Please note that unattended mode does not bring it out of sleep mode, it puts the device in a weird half-awake state.
So if you start a unattended mode while the device in suspended mode, it will not wake up the screen or anything. All unattended mode does is stop WM from suspending your application. Also the other problem is that it does not work on all devices, some devices power management is not very good and it will suspend you anyway no matter what you do.