Java - Android Programming - Loop Fail
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/10492182/java-android-programming-loop-fail">Java / Android Programming - Loop FAIL</a>  </p>
</blockquote>



<p>What i am trying to do:
To throw a toast once an hour.
What's the problem:
The while loop has the appropriate interval only the first time it's executed. 
The second time no interval between the toasts is added. Note that the code included inside the while loop is debugging and working perfectly. The only problem is the delay between the toasts.</p>

<pre><code> if (SelectedOption == 1) {
    int count = 1;
    while (count &lt;= 10) {               
         final Handler handler = new Handler();
         Timer t = new Timer();
         t.schedule(new TimerTask() {
             public void run() {
                handler.post(new Runnable() {
                    public void run() {
                    db.open();
                    String fact = "";
                    fact = db.getRandomEntry();
                    Context context = getApplicationContext();
                    CharSequence text = fact;
                    int duration = Toast.LENGTH_LONG;
                    Toast toast = Toast.makeText(context, text, duration);
                    toast.show();
                    db.close();
               }
               });
          }
      }, 3600000);
      count++;
   }
    } else if (SelectedOption == 2) 
            { ... // Something similar using different approach }
</code></pre>
