execute thread and invalidate screen in every second in wear OS android

153 views Asked by At

I want to show seconds in a watchface. In normal mode as well as in ambient mode. General Handler thread Handler handler = new Handler( /* Runnable{ invalidate(); handler.postDelayed(this, 1000);}*/ ) Works fine to update time and show it in screen while in normal mode but it sleeps and slips so far away and executes in random time while in ambient mode. Well this is nothing new and android doc and everyone says to update screen in every minute instead of a second. But I want the watchface to show seconds and that should be updated in every seconds despite battery life. And I can not find a answer for this.

I definitely tried ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();. All gave similar result and among these ScheduledExecutorServices schedule at fixed rate method gave worst performance. In my opinion AlarmManager is overkill for this purpose. The thread is created in onCreate method and is not changed.


Now someone please tell me a way to update the screen in every second while in or out of ambient mode.


Note: All thread works fine on wear OS emulator but on actual watch it shows this behaviour, that is executed in a random time, like in every 20 seconds.

0

There are 0 answers