public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome);
//        jumToOtherAct();
        new Thread(){
         public void run()
         {
          try {
           sleep(5000); 
           jumToOtherAct();              
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
         }
        }.start();
   
jumToOtherAct()方法就是做一个判断是否又网络,如果没有网络就弹出一个dialog提示检查网络,但是程序报错, java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
该怎么解决呢?

解决方案 »

  1.   

    jumToOtherAct()这个方法里面你检查网络,会弹出dialog。就相当于,在其他线程操作UI线程,这样的情况在android里面是不允许出现的,建议使用handler发送消息更新UI线程,弹出dialog.
      

  2.   

    子线程里没有looper,因此不能直接在子线程里创建handler,如果要创建的话要生产一个looper
    public void run() {

        Looper.prepare();
        MyHandler handler = new MyHandler();
        Looper.loop();
    }
      

  3.   

    在线程中不能直接调用任何含有view的元素,必须通过发送一个handler.message进行更新