title: Android Countdown Timer in Broadcast receiver doesn't update TextView
body: <p>I am creating application which works with SMS service and <strong>FTP</strong> networking. </p>
  
  <p>If user does not establish connectivity, it will try to reconnect again in 30 seconds. </p>
  
  <p>I am using CountDownTimer with TextView to inform user about time left to reconnnect. </p>
  
  <p>Either it will be successful or it will start counting again. </p>
  
  <p>My problem is, that if counter restarts while activity is in background or the screen is locked, TextView keeps showing number <strong>"1"</strong> (it won't update) until the timer restarts again in foreground (but updating numbers without timer restart works fine in backround or lock, I am using wakelock in my foreground service).</p>
  
  <p>After counter restarts again (so it won't stop counting) while application is in foreground, everything comes back to normal, TextView updates from freezed <strong>"1" to "30"</strong> and starts counting down to <strong>"1"</strong>. </p>
  
  <p>I think problem will be somewhere in communication between counter thread and background activity with UI, but I don't know nothing more about it.</p>
  
  <p>I tried several things like:</p>
  
  <ol>
  <li>creating setter and getter for miliseconds and update them in each
  tick, then try to update textview from <code>onReume()</code>, didn't work. </li>
  <li>create local variable for TextView inside timer, initialize it inside <code>onTick()</code> and
  try to update text from there, also didn't work.</li>
  </ol>
  
  <p>Thanks everyone for help, I will appriciate any advices.</p>
  
  <p>Part of code relative to question:</p>
  
  <pre><code>private CountDownTimer cdt = null;
  private final TextView getTextView_ActivityMainMenu_Timer(){
    return (TextView) findViewById(R.id.ActivityMainMenu_TextView_Timer);
  }
  
  private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
  
      if(intent.getBooleanExtra("KEY_FAILED", false)){
  
        cdt = new CountDownTimer(30000, 1000) {
  
          public void onTick(long millisUntilFinished) {          
            getTextView_ActivityMainMenu_Timer().setText("" + millisUntilFinished / 1000);                             
          }
  
          public void onFinish() {                        
            ;                     
          }
  
        }
        .start();
  
      }
      else
      {
        if(cdt != null)
          cdt.cancel();
      }
    }
  }; 
  </code></pre>