The differences between the code for the emulator and the code for a real device

The Android developers can use Sensor Simulator to test their applications, in particular when they use sensors such as accelerometer or compass.
In this post I explain the differences in the code for an activity that runs on the emulator or a real device, and I don’t discuss how to install or launch the emulator, for those topics you can refer to Sensor Simulator.
Switching from the emulator to the real device and vice versa you need to make some code changes and these changes can be divided into 4 points.

  1. different imports
  2. connection to the simulator in the onCreate method (this part is missing in the current code for the device)
  3. different listeners in the onResume method
  4. different ways to get the type of sensor in the onSensorChanged method

Continue reading “The differences between the code for the emulator and the code for a real device”