There will be cases where your app needs to listen and process the sensor values in the background. Such cases cannot be handled using the activity code structure. We need to use the Android service to handle background sensor processing. Let's discuss the background processing scenario with an example.
In our example, we will be playing a small MP3 sound when somebody picks up or handles the phone. We will call this event the phone handling event, and we will use the Android background service to continuously process the gyroscope sensor values to detect this phone-handling event. The gyroscope gives the rate of rotation of the phone in each x, y, and z axis. When your phone is kept still, there is no, or a very low rate of rotation reported as a value by gyroscope, but when the phone is picked up or handled, the value of rate of rotation goes very high. We will use this logic to define our...