带有线程的对话框消息

时间:2015-01-08 14:40:48

标签: java android multithreading user-interface

我正在开发Android应用程序,其中我有一个登录按钮onclick它将从一个线程中的Internet获取一些数据并在下一页显示。虽然它正在获取数据我正在显示一个对话框showin ga message“Loading ....”但是当我点击按钮时线程在后台执行但它没有显示对话框:(页面看起来像是被攻击了。这里是我正在使用的代码片段。

                   showdialog();

                    //**********************
                        Thread  t = new Thread(){
                        public void run(){
                            new Downloader().DownloadHandler();
                        }
                    };

                    t.start();

                    t.join();
                    _dialog.cancel();
                    Intent intent = new Intent(context, MainActivity.class);
                           startActivity(intent);   
}
public void showdialog()
 {
 _dialog = ProgressDialog.show(this, "Loading.....", "Please wait, we are on job.", true);
}

请分享是否有其他更好的方式来实现相同/或任何其他最佳方式向用户显示内容即将发布。 请告诉我他们是否还有其他更好的。

1 个答案:

答案 0 :(得分:0)

未显示

 t.join();

使用join暂停ui线程并让它等到t完成执行。您应该使用另一种方法,例如,您可以实现委托模式,通知UI线程,您的线程已完成其执行,以及您要关闭对话框并启动新活动。

相关问题