Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to avoid Admob blocking the UI thread
  2. public class LayoutTestActivity extends Activity {
  3.  
  4.     @Override
  5.     public void onCreate(Bundle savedInstanceState) {
  6.         super.onCreate(savedInstanceState);
  7.         setContentView(R.layout.main);
  8.  
  9.         long now = System.currentTimeMillis();
  10.  
  11.         new AdView(this, AdSize.BANNER, "MY_ID");
  12.  
  13.         Log.e("Admob Test","The UI was blocked "+(System.currentTimeMillis()-now)+"ms");
  14.     }
  15. }
  16.        
  17. public class LayoutTestActivity extends Activity {
  18.  
  19. @Override
  20. public void onCreate(Bundle savedInstanceState) {
  21.     super.onCreate(savedInstanceState);
  22.     setContentView(R.layout.main);
  23.  
  24.     long now = System.currentTimeMillis();
  25.  
  26.     new Thread(new Runnable() {
  27.  
  28.         public void run() {
  29.             new AdView(this, AdSize.BANNER, "MY_ID");              
  30.         }
  31.     }).start();
  32.  
  33.     Log.e("Admob Test","The UI was blocked "+(System.currentTimeMillis()-now)+"ms");
  34. }