Trouble with getSystemService(SENSOR_SERVICE) - Already implemented context
<p>I'm trying to create a Service for my Gyroscope in Android, but I keep having trouble with getSystemService.</p>

<p>I've been searching through the forums, trying to find a solution, but in most cases it is a matter of simply importing the context from the MainActivity.</p>

<pre><code>public class GyroData implements SensorEventListener {

private final Context mContext;
protected SensorManager mSensorManager;

public GyroData(Context context) {
    mContext = context;
    mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE);
}
</code></pre>

<p>As you can see above, I've already done that, yet I'm still getting the following error.</p>

<pre><code>java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{sw806f16.p8project/sw806f16.p8project.CameraActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
at sw806f16.p8project.GyroData.setupSensorManager(GyroData.java:24)
</code></pre>

<p>EDIT: Added code from MainActivity</p>

<pre><code>public class CameraActivity extends Activity implements LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
public static final String TAG = "CameraActivity";

LocationService gps = new LocationService(this);
GyroData gyro = new GyroData(this);
</code></pre>