views:

214

answers:

2

when I put the setContentView in thread as below, it crashes while running in emulator.

      new Thread(){
          public void run() {           
               setContentView(R.layout.main_layout);
          }  
      }.start();
+2  A: 

that is because setContentView cannot be called from a non-UI thread.

Samuh
+1  A: 

You could try...

runOnUiThread(new Runnable(){

  public void run() {
    setContentView(R.layout.main_layout);

  }});

.. but be careful as the convention is to do setContentView(..); in onCreate() on the default thread there.

Jim Blackler
Thanks,It works. But my aim is show dialog and load layout in background by using thread. I raised a new question for the same
Maneesh