Android Timer update UI between multiple tasks
        Posted  
        
            by 
                Rilcon42
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Rilcon42
        
        
        
        Published on 2013-06-30T04:18:26Z
        Indexed on 
            2013/06/30
            4:21 UTC
        
        
        Read the original article
        Hit count: 192
        
I have tried multiple ways to have a single persistent timer update the ui in multiple activities, and nothing seems to work. I have tried an AsyncTask, a Handler, and a CountDownTimer. The code below does not execute the first Log.i statement.... Is there a better way to start the timer (which must be called from another class) in Main (which is the only persistent class)?
 public static void MainLawTimer()
{
    MainActivity.lawTimer = new CountDownTimer(MainActivity.timeLeft, 1000) 
    {
           public void onTick(long millisUntilFinished) 
           {
               Log.i("aaa","Timer running. Time left: "+MainActivity.timeLeft);
              MainActivity.timeLeft--; 
              if(MainActivity.timeLeft<=0)
              {
                //do stuff
              }
              else
              {
                  //call method in another class                          
              }  
           }
© Stack Overflow or respective owner