Android 防止锁屏服务暂时停止运行

    private WakeLock mWakeLock;  
    //申请设备电源锁  
    private void acquireWakeLock(Context context)  
    {  
        if (null == mWakeLock)  
        {  
            PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);  
            mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE, TAG);  
            if (null != mWakeLock)  
            {  
                mWakeLock.acquire();  
            }  
        }  
    }  
    //释放设备电源锁  
    private void releaseWakeLock()  
    {  
        if (null != mWakeLock)  
        {  
            mWakeLock.release();  
            mWakeLock = null;  
        }  
    }  

你可能感兴趣的:(android)