I am working on Android App and unable to synchronize View with Hardware.
Let me explain.
1) I mute and unmute microphone of Android based on random values (which are random sleeps) stored in array A, from within run method of Thread 1.
2) I draw blue pulses that reflects the mutes of microphone. This is done by independent View class.
3)I move a red line across the graph drawn in above view, by calling from within onTick of a countdown timer.
I start the two threads one after other, this way:
Thread1.start
counter.start();
How to synchronize both of these, I want to do three things at a time and avoid multiple threads. Three things are: Draw the pulses (which is constant) , make the red line move across x axis and touch the blue pulse as soon as the phone is muted, and keep moving every second, the width of pulse reflects duration of delay. as soon as microphone is about to be unmuted, red line should leave the pulse and move forward.
Currently, code is doing what I want. but there is no synchroization. Either microphone does its job first, or graph moves fast. They are not in Sync.
Is there a way to hold a thread, force it to behave as coutdowntimer or sync both of them.
I cannot embed the red line movement in thread 1 because, it will have to progress across x axis every second.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…