Android 黑屏问题

发布于 2024-10-16 06:57:09 字数 228 浏览 2 评论 0原文

我正在将控制权从 Activity1 转发到 Activity2

在 Activity2 中 我在一些网络操作之后在 setContentView 之前在 onCreate 中使用 ProgressDialog

我正在使用 setcontentView

但 ProgressDialog 根本没有显示...

如何存档 ProgressDialog。

谢谢。

I m forwarding control from Activity1 to Activity2

In Activity2
i am using progressDialog in onCreate before setContentView

after some network operation i am using setcontentView

but progressDialog is not showing at all...

how to archive progressDialog.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赢得她心 2024-10-23 06:57:09

请发布一些代码以便我们确定,但我敢打赌这是因为您的网络操作。正如我对关于 toast 消息的这个问题的回答一样,当您调用创建一个对话框,我认为您请求 UI 线程创建一个对话框,它不一定会在 show() 方法后立即发生返回。如果您随后在 onCreate 中执行网络操作,那么这将阻塞 UI 线程,直至其完成,从而阻止 Dialog 出现。您应该将所有网络请求移至 AsyncTaskThread/Handler 组合中。

Please post some code so that we can be sure, but I'm betting its because of your network operation. As with my answer to this question about toast messages, when you make a call to create a dialog, I think you are requesting that the UI thread create a dialog, it doesn't necessarily happen as soon as the show() method returns. If you then perform a network operation in onCreate then this will block the UI thread until it completes, preventing the Dialog from appearing. You should move any network requests out into either an AsyncTask or a Thread/Handler combination.

遥远的她 2024-10-23 06:57:09

不要忘记调用 ProgressDialog 的 show():

    ProgressDialog dialogLoad;
    dialogLoad = ProgressDialog.show(this, "", "Loading...", true);

    //doing work
    //when done with work
    dialogLoad.dismiss();

=================================

也考虑使用线程:

ProgressDialog dialogLoad;
    dialogLoad = ProgressDialog.show(this, "", "Loading...", true);

final Handler handler = new Handler() {
           public void handleMessage(Message msg) {
              dialogLoad.dismiss();
              }
           };
        Thread updateData = new Thread() {  
           public void run() {

           //************make calls to web service/network***************

              handler.sendEmptyMessage(0);
              }
           };
          updateData.start();

Don't forget to call show() of ProgressDialog:

    ProgressDialog dialogLoad;
    dialogLoad = ProgressDialog.show(this, "", "Loading...", true);

    //doing work
    //when done with work
    dialogLoad.dismiss();

===============================

Think about using threads too:

ProgressDialog dialogLoad;
    dialogLoad = ProgressDialog.show(this, "", "Loading...", true);

final Handler handler = new Handler() {
           public void handleMessage(Message msg) {
              dialogLoad.dismiss();
              }
           };
        Thread updateData = new Thread() {  
           public void run() {

           //************make calls to web service/network***************

              handler.sendEmptyMessage(0);
              }
           };
          updateData.start();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文