title: Repeating the process : displaying a view for an random time then make it invisible for an random time
body: <p>The title says it all. I want to make a view into an infinite loop of random visibility and invisibility. This is how I approached it :-</p>
  
  <p>First I created two methods to get Random time getRandomWaitTime() and getRandomDisplayTime(). These methods are well defined and tested (in Log) and are working as desired. Both these methods return a random value as int in millisecond as </p>
  
  <pre><code>getRandomWaitTime()     :   3000-6000
  getRandomDisplayTime()  :   3000-5000
  </code></pre>
  
  <p>Now I created one ImageView fruit[0], set it initially as invisible and after that the following code is executed :</p>
  
  <pre><code>fruit[0].postDelayed(new Runnable() {
              @Override
              public void run() {
                  fruit[0].setVisibility(View.VISIBLE);
                  fruit[0].postDelayed(new Runnable() {
                      @Override
                      public void run() {
                          fruit[0].setVisibility(View.INVISIBLE);
                      }
                  }, getRandomDisplayTime());
                  fruit[0].postDelayed(this, getRandomWaitTime());
                  }
          }, getRandomWaitTime()); 
  </code></pre>
  
  <p>The code compiles, executes as well, the ImageView goes through infinite cycle of visibility and invisibility <strong>but the time for which it is set as visible or invisible doesn't seem to have minimum value of 3000ms</strong> Sometimes it feels like it is visible for a 500ms and then gone invisible. I have tried a ton of things such as using Handler.postDelayed instead of View.postDelayed but this doesn't seem to work.</p>
  
  <p>Interesting thing happens when I remove all <code>getRandomWaitTime()</code> and <code>getRandomDisplayTime()</code> methods from postDelayed method and replace then with a constant like 3000.</p>
  
  <p>The activity starts. At first fruit[0] is set to invisible. After 3000ms it comes visible and <strong>stays there</strong>. Nothing happens after it. No more switching to invisibility. I just stays there.</p>
  
  <p>So what could be the possible reasons for all these sorcery problems?</p>