简体   繁体   English

无法在尚未调用looper.prepare的线程内创建处理程序

[英]cant create handler inside thread that has not called looper.prepare

Note : I know there are many questions related to this, but still I am not convince, so asking. 注意 :我知道与此相关的问题很多,但我仍然不能说服,所以请您提出。

I am getting cant create handler inside thread that has not called looper.prepare when I try to show the dialog. 当我尝试显示对话框时,无法在未调用looper.prepare的线程内创建处理程序。

Here is my code... 这是我的代码...

//this method is called from a different method based on some condition which is inturn called on click a button //此方法是根据某些条件从不同的方法调用的,该条件又是在单击按钮时调用的

 private void download() {
    thread = new Thread() {
     public void run() {
    /**** Downloads each tour's Tour.plist file ****/
            try {
                // do many heavy operations here, like download, 
                //calling web webvice and starting another activity

               This comes at the end

                Intent toAudio = new Intent(TourDescription.this,Audio.class);
                startActivity(toAudio);
         } catch (Exception e) {
       }  

       }
    }; 
    thread.start();
 }

Now before this actity gets called I am trying to show a dialog. 现在,在调用该活动之前,我试图显示一个对话框。 I am trying to place that just before calling Intent. 我正试图在致电Intent之前将其放置。

Can any body please tell me how to do this, as I am not understanding how to solve this 任何人都可以告诉我该怎么做,因为我不了解如何解决这个问题

you cannot show a dialog from a child thread. 您无法从子线程显示对话框。 A dialog can only be showed from within the UI thread/main Thread. 只能从UI线程/主线程内显示对话框。

try this from inside the child thread 从子线程内部尝试

runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // TODO show dialog....

        }
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在未调用looper.prepare()的线程内创建处理程序 - cannot create handler inside thread that has not called looper.prepare() 无法在未调用Looper.prepare()的线程内创建处理程序 - Can not create handler inside thread that has not called Looper.prepare() 无法在尚未调用looper.prepare,eventlisteners的线程内创建处理程序 - Cant create handler inside thread that has not called looper.prepare, eventlisteners 无法在尚未调用looper.prepare android的线程内创建处理程序 - cant create handler inside thread that has not called looper.prepare android Android:无法在尚未调用looper.prepare的线程内创建处理程序 - Android: cant create handler inside thread that has not called looper.prepare 无法在Handler()内未调用Looper.prepare()的线程内创建处理程序 - Can't create handler inside thread that has not called Looper.prepare() inside Handler() 无法在尚未调用弯针准备的线程内创建处理程序 - cant create handler inside thread that has not called looper prepare Android处理程序:无法在尚未调用Looper.prepare()的线程内创建处理程序 - Android handler: Can't create handler inside thread that has not called Looper.prepare() Handler或runOnUiThread解决方案“无法在未调用Looper.prepare()的线程内创建处理程序” - Handler or runOnUiThread solution for “Can't create handler inside thread that has not called Looper.prepare() ” Android线程错误-无法在未调用Looper.prepare()的线程内创建处理程序 - Android thread error - Can't create handler inside thread that has not called Looper.prepare()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM