title: Passing code as parameter
body: <p>I'm using this code to show messages:</p>
  
  <pre><code>Common.getHandler().post(new Runnable(){
      public void run(){
          Toast.makeText(Common.getContext(), "Text...", Toast.LENGTH_SHORT).show();
      }
  });
  </code></pre>
  
  <p>Common is a class of mine, and getHandler() will return a handler created in an activity. This way I can call Toast from outside activities. 
  This is a good aproach, and it works fine, but I'm wondering if there is another way to make that code a little bit cleaner/shorter.</p>
  
  <p>Something like:</p>
  
  <pre><code>Common.run({
      Toast.makeText(Common.getContext(), "Text...", Toast.LENGTH_SHORT).show();
  });
  </code></pre>
  
  <p>And the run() method should encapsulate the code passed as argument inside a Runnable.</p>
  
  <p>AFAIK this is called closure and it's possible in Javascript.</p>
  
  <p>Regards!</p>