对于一些 对于一些android2.3系统休眠后,你的服务可能也不行了,需要进行单独处理,具体代码如下:
// BroadcastReceiver for handling ACTION_SCREEN_OFF.
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent)
{
// Check action just to be on the safe side.
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
// Unregisters the listener and registers it again.
releaseWakeLock();
acquireWakeLock();
}
}
};
private void sendBroad(String filter,String sKey,int nValue){
Intent i = new Intent(filter);
i.putExtra(sKey, nValue);
sendBroadcast(i);
}
private void acquireWakeLock()
{
if (wl != null)
{
wl.release();
}
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "gmlc.com.wuliu");
if (null != wl) {
wl.acquire();
wl.setReferenceCounted(false);
}
}
private void releaseWakeLock()
{
if (null != wl) {
wl.release();
wl = null;
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)