-1

i got some strange behavior here in a AsyncTask. I'm trying to load a pdf asynchronously to a PDFView (I used this library)

Here is my code:

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_simple_fileview);

        setupUI();

        startFile();

    }

    private void startFile() {
        if(FileUtilities.getFileExtension(file.getName()).equals("pdf")) {

            new loadPDFTask(this).execute(file);

        }else{
            try{
                VideoView mVideoView = (VideoView)findViewById(R.id.videoview);
                mVideoView.setVisibility(View.VISIBLE);
                Uri uri = Uri.parse(file.getAbsolutePath());
                mVideoView.setVideoURI(uri);
                mVideoView.requestFocus();
                mVideoView.start();
            }catch (Exception e){
                Log.e("Fehler", "Video konnte nicht geladen werden");
            }
        }
    }

    private void setupUI() {
        String path = getIntent().getExtras().getString("file");
        file = new File(path);
        mNextFile = (ImageView)findViewById(R.id.next_file);
        mPreviousFile = (ImageView)findViewById(R.id.previous_file);
        pdfView = (PDFView) findViewById(R.id.pdfview);
    }


    //lädt PDF asynchron und zeigt ProgressDialog an
    private class loadPDFTask extends AsyncTask<Object,String,File> {

        private Context context;


        public loadPDFTask(Context ctx){
            context = ctx;
            dialog = new ProgressDialog(context);
            dialog.setMessage("Loading PDF...");
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            dialog.show();
        }
        @Override
        protected File doInBackground(Object... args) {
            File file = (File)args[0];
            pdfView.fromFile(file)
                    .defaultPage(1)
                    .showMinimap(false)
                    .enableSwipe(true)
                    .load();
            return file;
        }
        @Override
        protected void onPostExecute(File unused) {
            super.onPostExecute(unused);
            if(dialog!=null) {
                dialog.dismiss();
            }
        }
    }

My problem is, it executes the onPreExecute method and is correctly showing the ProgressDialog. But from there it get stuck and is loading and loading forever.

I checked the running Threads and saw, that the AsyncTask Threads are all on waiting. I guessed it has something to do with that fact and I need to try it with a ThreadPoolExecuter. This is what a lot of answers on similar problems in SO proposed. Anyway, I can't get it to work.

Anyone an idea, what I might done wrong?

Here is a part of my Logcat while it is loading the pdf although I don't think this is gonna help:

07-09 17:35:58.370  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x1e000001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:58.370  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 0.147222 0.000000 0.000000 -0.148148 0.000000 80.000000
07-09 17:35:58.370  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 106 80
07-09 17:35:58.370  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:58.490  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:58.490  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:58.520  10080-10098/lp.german.bischofshofpresenter.app D/dalvikvm﹕ GC_FOR_ALLOC freed 3520K, 26% free 14324K/19207K, paused 21ms
07-09 17:35:58.530  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x1ee00001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:58.530  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 0.000000 256.000000
07-09 17:35:58.530  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:58.530  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:58.750  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:58.760  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:58.760  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x1fc00001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:58.760  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 -256.000000 256.000000
07-09 17:35:58.760  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:58.760  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:58.990  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:58.990  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:59.000  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x20a00001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:59.000  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 -256.000000 512.000000
07-09 17:35:59.000  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:59.000  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:59.080  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:59.090  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:59.090  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x21800001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:59.090  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 0.000000 512.000000
07-09 17:35:59.090  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:59.090  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:59.260  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:59.260  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:59.270  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x22600001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:59.270  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 -512.000061 256.000000
07-09 17:35:59.270  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:59.270  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:59.330  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:59.330  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:35:59.370  10080-10082/lp.german.bischofshofpresenter.app D/dalvikvm﹕ GC_CONCURRENT freed 3203K, 33% free 13048K/19207K, paused 2ms+4ms
07-09 17:35:59.370  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView(0x23400001).nativeCreateView(0x663138, 0x6d7e80)
07-09 17:35:59.370  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Matrix: 1.066667 0.000000 0.000000 -0.948148 -512.000061 512.000000
07-09 17:35:59.370  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Viewbox: 0 0 256 256
07-09 17:35:59.370  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ doing the rendering...
07-09 17:35:59.460  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ Converting image buffer pixel order
07-09 17:35:59.460  10080-10098/lp.german.bischofshofpresenter.app D/PdfDroid﹕ PdfView.nativeCreateView() done
07-09 17:36:05.700  10080-10080/lp.german.bischofshofpresenter.app D/OpenGLRenderer﹕ Flushing caches (mode 0)
Igl3
  • 4,900
  • 5
  • 35
  • 69
  • Other async tasks are waiting because this one isn't done yet. It isn't done yet... either the pdf is really complex to load (I've used professional PDF libraries that can chug for 30s to a few minutes on complex architectural pdfs with a few pages) or the library got itself in an infinite loop somewhere. You're probably going to have to debug into the library. – Gabe Sechan Jul 09 '14 at 15:30
  • Are you sure that the pdf file isn't corrupted or something? And are you sure that the library you ist isn't already asynchronous? I don't see why you would need a thread pool executor, you are only running one task. And if you were running multiple tasks at the same time this still wouldn't cause the problems you seem to have. Most likely there is something wrong with the library or with the file. – Xaver Kapeller Jul 09 '14 at 15:31
  • Same behavior when i call the load function without asynctask...but when I started the Activity from another activity than main activity it works like charm. Should I post my mainActivity too? – Igl3 Jul 09 '14 at 15:37

1 Answers1

0

Seems like the library shouldn't go into an AsyncTask. The library might already be asynchronous, since it lets you register an onLoad callback. Have you tried following the example in the Readme for that library? Just run the call in your main thread (without the AsyncTask), and if you need to do something after it's done loading, register an onLoad callback.

Wild Pete
  • 158
  • 1
  • 1
  • 6