I'm developing a wearable app and I've noticed a strange behaviour.
I have a class FooService extends Service implements SensorEventListener
and I've override onSensorChanged()
method:
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
if (sensorEvent.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
Log.e(TAG, getString(R.string.err_wrong_sensor_registered));
return;
}
float x = sensorEvent.values[0];
float y = sensorEvent.values[1];
float z = sensorEvent.values[2];
...
}
This service is started from FooActivity extends WearableActivity
- here i override onEnterAmbient()
, onExitAmbient()
methods doing some UI changes only (no interaction with Service).
Everything works perfect I'm getting onSensorChanged() calls when device is plugged to USB both is Ambient Mode and in normal mode but unfortunatelly i'm not getting calls 3 seconds after device entered ambient mode when not connected to USB.
Q1: So my question is why onSensorChanged() method is not invoked when on Ambient Mode and not connected to USB?
I' have manage to force onSensorChanged() when not connected to USB and in Ambient Mode using manual wakeLock in Activity
wakeLock = mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock");
but
Q2: Shouldn't Activity has wakeLock acquired automaticaly by ambientMode mechanism?
Any suggestions will be appreciated :)