I have a countdown timer that onFinished I want to have the screen change colors repeatedly.
I’m trying:
public void onFinish() {
findViewById(R.id.screenid).setTag("BLACK");
_timer2=new Timer();
_timer2.scheduleAtFixedRate(Flashscreen, 0,1700);}
TimerTask Flashscreen = new TimerTask()
{
public void run() {
if ( findViewById(R.id.screenid).getTag()=="BLACK" )
{
findViewById(R.id.screenid).setBackgroundColor(Color.BLUE);
findViewById(R.id.screenid).setTag("BLUE");
return;
}
if (findViewById(R.id.screenid).getTag()=="BLUE")
{
findViewById(R.id.screenid).setBackgroundColor(Color.BLACK);
findViewById(R.id.screenid).setTag("BLACK");
return;
}
}};
But it will only change the color to blue once. What’s happening wrong?
Can you try putting both changing of color to run on uithread.
Something like below