例如我有一个应用程序,计算有多少时间拍照键为pressed。锁定的应用程序无法正常工作的屏幕后,那么有没有什么办法可以让计算presses当屏幕被锁定?
For example I have an app that counts how many time Camera button was pressed. After locking the screen the app is not working, so is there any way to keep counting presses when screen is locked?
运行的应用程序和服务都暂停,当手机被锁定,但你可以掌握WAKE_LOCK关键,做你的任务
Running Apps and services are pause when the phone is locked, but you can acquire WAKE_LOCK key and do your task
PowerManager mgr = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
WakeLock wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyWakeLock");
wakeLock.acquire();
这将持有的CPU开,即使屏幕关闭
this will hold the CPU open even if the screen off
上一篇:无法与API级别10创建Android项目,因为没有兼容的主题可用级别、项目、主题、API
下一篇:任何约定一个IEnumerable< T>报告不变性等特点?特点、报告、不变性、IEnumerable