【问题标题】:Async program flow/show ProgressDialog异步程序流程/显示 ProgressDialog
【发布时间】:2013-11-25 23:39:55
【问题描述】:

我有一些代码 a) 需要大约 10..20 秒来执行 b) 返回一个用于进一步处理的值 c) 被用户调用

因此我创建了这样的结构:

ProgressDialog pd = new ProgressDialog(ctx);  
pd.setCancelable(false);
pd.setCanceledOnTouchOutside(false);
pd.setTitle(ctx.getResources().getText(R.string.progress));
pd.setMessage(ctx.getResources().getText(R.string.wait_keygen));
pd.setIndeterminate(true);

returnValue=doSomeDifficultCalculationsHere();

pd.dismiss();

现在我的问题是:进度对话框没有显示,它似乎也被阻塞的 doSomeDifficultCalculationsHere() 函数阻塞了。

当我将 doSomeDifficultCalculationsHere() 放入自己的线程并执行 Thread.join() 以等待此函数的结果时,由于 Thread.join() 阻塞,因此也不会显示进度对话。

当我将 ProgressDialog 放入线程时,我得到一个异常。

那么,当我无法真正异步调用 doSomeDifficultCalculationsHere() 因为后续所有步骤都需要它的结果时,我还能如何解决这个问题并让 ProgressDialog 显示?

谢谢!

【问题讨论】:

    标签: android multithreading progressdialog


    【解决方案1】:

    你需要在returnValue=doSomeDifficultCalculationsHere();之前做pd.show()

    【讨论】:

    • 什么他妈的...你是对的,这完全没有!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    • 2014-06-13
    • 1970-01-01
    • 2014-12-04
    相关资源
    最近更新 更多