 <p>From your MainActivity:</p> <pre><code>Intent intent = new Intent(this, mySensor.class); intent.putExtra("type", Sensor.TYPE_LIGHT); </code></pre> <p>and within your service:</p> <pre><code>@Override public IBinder onBind(Intent intent) { mSensorManager= (SensorManager) getSystemService(Context.SENSOR_SERVICE); int type = intent.getExtras().get("type"); s= mSensorManager.getDefaultSensor(type); return null; } </code></pre> <p>then you can remove:</p> <pre><code>public mySensor(int type){ ... } </code></pre> <p>and eventually the code you wrote within the <code>onCreate</code>.</p>