Quickly switch between the code for the emulator to the code for the real device

In a previous post I explained the differences between the code for the emulator and the code for the real device, but the switch from one to another and vice versa is very cumbersome.
In this post I propose a way to switch quickly from one situation to another with few changes.
The specific code for the emulator has moved to a class that extends Activity (SimulatorActivity), and similarly, the specific code for the real device is moved to a class that extends Activity (DeviceActivity); both classes implement SensorEventListener.
The specific code for your app is contained in a class that extends SimulatorActivity or DeviceActivity; you override the methods onCreate, onResume and onPause and their first line of code must be a call to super.onCreate, super.onResume and super.onPause.
To quickly switch between the code for the emulator to the code for the real device you can simply change what class extends and change the import.

  • SimulatorActivity.java
  • DeviceActivity.java
  • MainActivity.java

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.