首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >progressDialog in onNewIntent

progressDialog in onNewIntent
EN

Stack Overflow用户
提问于 2014-04-25 00:21:32
回答 2查看 669关注 0票数 0

当我扫描NFC标签时,我正在使用onNewIntent。我想在扫描标签时显示ProgressDialog。我试着用一个线程,但它毁了我的应用程序。有什么方法可以在progressDialog启动时向onNewIntent展示?

代码语言:javascript
复制
public void onNewIntent(Intent intent) {
        setIntent(intent);
        Thread scanning = new Thread(new Runnable() {
            public void run() {
                ScanDialog = ProgressDialog.show(BorrowActivity.this,
                        "Scanning...", "scanning");
            }
        });
        scanning.start();
              .
              . //next code doing something
              .
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-25 22:17:39

最后,我用asyncTask修复了它。

代码语言:javascript
复制
public void onNewIntent(Intent intent) {
    setIntent(intent);
        ScanDialog = ProgressDialog.show(BorrowActivity.this,
                "Scanning...", "Scanning");

        try {
        new DoBackgroundTask().execute();
        } catch (Exception e) {
             //error catch here
        }
        ScanDialog.dismiss();

和AsyncTask:

代码语言:javascript
复制
private class DoBackgroundTask extends AsyncTask<Integer, String, Integer> {

    protected Integer doInBackground(Integer... status) {
     //do something
    }
    protected void onProgressUpdate(String... message) {
    }
    protected void onPostExecute(Integer status) {
    }
}
票数 0
EN

Stack Overflow用户

发布于 2014-04-25 00:30:27

不能在另一个线程上更新或使用UI:

解决方案:

调用主线程并更新其中的UI

代码语言:javascript
复制
    Thread scanning = new Thread(new Runnable() {
        public void run() {
            runOnUiThread(new Runnable() 
            {
               public void run() 
               {
                    ScanDialog = ProgressDialog.show(BorrowActivity.this,
                        "Scanning...", "scanning");
               }
            });

        }
 });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23282120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档