Recently i tried to implementing ambient mode in android wear watchface, after implement some coding, i found out that onAmbientModeChanged will not be called when turn into ambient mode (emulator), but turn to normal mode it will called twice, first trigger,the inAmbientMode is true, second trigger the inAmbientMode is false.
private class Engine extends CanvasWatchFaceService.Engine {
...
...
@Override
public void onAmbientModeChanged(boolean inAmbientMode) {
Log.e(TAG, "isInAmbientMode():" + inAmbientMode);
super.onAmbientModeChanged(inAmbientMode);
if (mLowBitAmbient) {
boolean antiAlias = !inAmbientMode;
setPaintAntiAlias(antiAlias);
}
invalidate();
updateTimer();
}
@override
public void onDraw(Canvas canvas, , Rect bounds){
...
for(int i=0;i<node.length;i++){
//drawing canvas
}
}
}
AndroidManifest.xml
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET"/>
What would it be the problem for not triggering when ambient is on? Is it a bug or i need to add some permission or class to trigger this? Any help would be appreciated.
EDIT: When ambient, the watchface won't redraw until it turn back to normal mode, then the watchface will draw the ambient watchface then only draw the normal watchface
After testing and debugging for something, i found out that the for loop is the main cause that didn't trigger the onAmbientModeChanged, after comment out the for loop, when ambient change, the onAmbientModeChanged will also trigger correctly but still don't know why it happen and solution.