Code example for HandlerThread

Methods: getLooperisAlivestart

			sensorEnabled = true;
			// create a new thread to run this sensor on 
			if (sensorHandlerThread == null)
				sensorHandlerThread = new HandlerThread("CameraLightSensor");
			// start the thread; 
			if (!sensorHandlerThread.isAlive())
			// create a handler on the thread to run the update and send functions 
			if (cameraLightValueHandler == null)
				cameraLightValueHandler = new Handler(sensorHandlerThread.getLooper());
			// add the runnable 
			if (updateAndSendValues == null)
						.post(updateAndSendValues = new UpdateAndSendCameraLightValues(0));
		} catch (Exception e) {
			Log.e(TAG, "Error in starting the Camera Light sensor: " + e.getMessage());
	public void stopLightSensing() { 
Experience pair programming with AI  Get Codota for Java