I have got an alarm manager and I am working with some tasks in background with alarm managers. I use wakelock for waking CPU in order to finish my background work which causes the error below. I have searched and found that a type of wakelock must be specified and I shouldn't use ACQUIRE_CAUSES_WAKEUP
. What should I use instead?
My code:
private static PowerManager.WakeLock wakeLock;
public static void acquirWakeLock(){
if(wakeLock!=null){
wakeLock.release();
}
PowerManager pm=(PowerManager) KITILApplication.getappContext().getSystemService(Context.POWER_SERVICE);
//Error is below line
wakeLock=pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP|PowerManager.ON_AFTER_RELEASE,"aqs_wake_lock");
wakeLock.acquire();
}
public static void releaseWakeLock(){
if(wakeLock!=null)
wakeLock.release();
wakeLock=null;
}
My Error:
Caused by: java.lang.IllegalArgumentException at android.os.PowerManager$WakeLock.<init>