在AsyncTask上使用GifTextView时挂起所有线程?

时间:2016-12-28 05:04:50

标签: android multithreading performance android-asynctask

我正在尝试将GifTextView用于我的动画。这AsyncTask实际上有效,但是当我使用GifTextView时需要很长时间。如果从此代码中删除GifTextView,则AsyncTask可以快速运行。

public class PDFCreate extends AsyncTask<String,String,String> {
    @Override
    protected String doInBackground(String... strings) {
        String FILE = Environment.getExternalStorageDirectory().toString()
                +"/TEST/PDF/"+Ex_date+".pdf";
        try {
                Document document = new Document(PageSize.A4);
                String root = Environment.getExternalStorageDirectory().toString();
                File myDir = new File(root + "/TEST/PDF");
                myDir.mkdirs();

                    PdfWriter.getInstance(document, new FileOutputStream(FILE));

                document.open();
                addMetaData(document,"LEAKS");
                addTitlePage(document,Ex_title);
                document.close();
        } catch (DocumentException e) {
            FILE = "Error Create Document";
        } catch (FileNotFoundException e) {
            FILE = "Cannot Create Document Path";
        }
        return FILE;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        GifTextView git = (GifTextView) findViewById(R.id.loading_gift);
        git.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onPostExecute(String st) {
        super.onPostExecute(st);
        git.setVisibility(View.GONE);
        ViewDialog alert = new ViewDialog();
        alert.showDialog(detail.this,"File have been saved on : \n" + st);
    }
}

我的问题是,如何在不降低程序速度的情况下使用GifTextView

1 个答案:

答案 0 :(得分:1)

EthicsDev ok谢谢。最后我使用Glide来加快我的AsyncTask。删除GifTextView

      ImageView imageView = (ImageView) findViewById(R.id.loading_gift);
        GlideDrawableImageViewTarget imageViewTarget = new GlideDrawableImageViewTarget(imageView);
        Glide.with(leaks_detail.this).load(R.drawable.loading).override(200,200)
                .into(imageViewTarget);