Code example for PowerManager.WakeLock

Methods: setReferenceCounted

0
		public Receiver(Runnable runnable) {
		    this.runnable = runnable;
 
		    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
		    this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
		    this.wakeLock.setReferenceCounted(true);
		} 
 
		@Override 
		public void onReceive(Context context, Intent intent) {
			/* 
			 * The #run() call can block, so do it on a background thread. The 
			 * phone could sleep after onReceive() exits but before the 
			 * background thread completes, so to prevent that, take a wakelock 
			 * before returning and release it after the background thread 
			 * completes. 
			 */ 
			wakeLock.acquire();
			new Thread(new Runnable() {
				@Override 
				public void run() {