进度对话框不会显示与异步任务 [英] Progress dialog wont show with async task

查看:113
本文介绍了进度对话框不会显示与异步任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已现在搜索这个答案一段时间。我有一个下载需要我的应用程序数据库中的一个异步任务,而这是下载我的应用程序不能做任何事情,因为所有它引用在此文件中的数据,我有应用程序等待文件被下载,但我试图显示进度对话框让用户知道,而他们等待这一切的发生有事情发生。

I have been searching for an answer for this for some time now. I have an async task that downloads the database needed for my app, while this is downloading my app cant do anything as all the data it references is in this file, i have the app waiting for the file to be downloaded but i am attempting to show a progress dialog so the user knows something is happening while they wait for this to happen.

我的code是目前

public class fileDownloader extends AsyncTask<Void, Integer, SQLiteDatabase> 
{
    private File dbFile;
    private ProgressDialog progressDialog;
    private Context context;
    private SQLiteDatabase database;
    private SQLiteDatabase.CursorFactory factory;

    public fileDownloader(Context c)
    {
        super();
        context = c;
    }
    @Override    
    protected void onPreExecute() 
    {       
        super.onPreExecute();
        progressDialog = new ProgressDialog(this.context);
        progressDialog.setMessage("Downloading Database...");
        progressDialog.setCancelable(false);
        progressDialog.setIndeterminate(true);
        progressDialog.show();
    }

    @Override
    protected SQLiteDatabase doInBackground(Void... v) 
    {        
     ....
    }

    @Override
    protected void onPostExecute(SQLiteDatabase db1)
    {
        progressDialog.dismiss();
    }

但什么也不显示我也曾尝试直接调用ProgressDialog.show在pre执行并没有运气这移动到调用活动。

however nothing shows up i have also tried directly calling ProgressDialog.show in the pre execute and moving this to the calling activity with no luck.

请大家帮忙!

推荐答案

解决这个是看调用类的UI线程被阻塞为此对话框一直没有露面。

the solution to this was to look at the calling class the UI thread was getting blocked therefor the dialog never showed up.

这篇关于进度对话框不会显示与异步任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆