title: Android Simon sequence in UIThread
body: <p>I am very new in Android, as a project, am doing a simon says game, and I'm having some problems representing the sequence to follow.</p>
  <p>I tried to use a normal thread to make it follow a line (for example, the first button is lighten during X seconds, then turns off, then the yellow one....), but it didn't make it, because only the threads that created the view hierarchy can manipulate that view (in this case was the UI thread). So I had to load all the method in that thread with runOnUiThread, and at that point it worked almost perfect, because now the sequence is shown up but the frames don't. The Log tells me:</p>
  <blockquote>
  <p>I/Choreographer: Skipped 116 frames!  The application may be doing too much work on its main thread.</p>
  </blockquote>
  <p>I have been looking for everywhere and I don't find alternatives for simulate the sequence. I leave here the code of the method.</p>
  <pre><code>public void createSequence(){
  
  
      new Thread() {
          public void run() {
  
                    runOnUiThread(new Runnable() {
                          @Override
                          public void run() {
  
                              sequence.clear();
                              for(byte i=0;i&lt;rounds;i++){
                                  add=r.nextInt((4 - 1) + 1) + 1;
  
                                  if (add == 1) {
                                      btn1.setBackgroundResource(R.drawable.button1_pressed);
  
                                      try {
                                          Log.i(&quot;Waiting for 1.&quot;,&quot;Waiting for 1.&quot;);
                                          Thread.sleep(time);
                                          btn1.setBackgroundResource(R.drawable.button1);
                                      } catch (InterruptedException e) {
                                          e.printStackTrace();
                                      }
  
                                      Log.i(&quot;Value:&quot;, &quot;1.&quot;);
                                  } else if (add == 2) {
                                      btn2.setBackgroundResource(R.drawable.button2_pressed);
                                      try {
                                          Log.i(&quot;Waiting for 2.&quot;,&quot;Waiting for 2.&quot;);
                                          Thread.sleep(time);
                                          btn2.setBackgroundResource(R.drawable.button2);
                                      } catch (InterruptedException e) {
                                          e.printStackTrace();
                                      }
  
  
  
                                      Log.i(&quot;Value:&quot;, &quot;2.&quot;);
                                  } else if (add == 3) {
                                      btn3.setBackgroundResource(R.color.colorpressedbutton3);
                                      try {
                                          Log.i(&quot;Waiting for 3.&quot;,&quot;Waiting for 3.&quot;);
                                          Thread.sleep(time);
                                          btn3.setBackgroundResource(R.drawable.button3);
                                      } catch (InterruptedException e) {
                                          e.printStackTrace();
                                      }
  
  
                                      Log.i(&quot;Value:&quot;, &quot;3.&quot;);
                                  } else {
                                      btn4.setBackgroundResource(R.color.colorpressedbutton4);
                                      try {
                                          Log.i(&quot;Waiting for 4.&quot;,&quot;Waiting for 4.&quot;);
                                          Thread.sleep(time);
                                          btn4.setBackgroundResource(R.drawable.button4);
                                      } catch (InterruptedException e) {
                                          e.printStackTrace();
                                      }
  
                                      Log.i(&quot;Value:&quot;, &quot;4.&quot;);
                                  }
  
  
                                  sequence.add(add);
                              }
                          }
                      });
              }
      }.start();
  
  }
  </code></pre>