Viewing 10 posts - 1 through 10 (of 13 total)
  • Author
    Posts
  • #10411 Reply

    Ben

    Dear Dr. Plug,

    plugpdf.openFile(path, “”);

    is run on the main thread seems, because UI blocks while loading and Android warns that using a AsyncTask is impossible.

    This causes lag for the user. It also seems that load obviously takes up the most startup time for the activity.

    It seems to be because:

    is run from openFile and thus the native load call is executed on the main thread.

    Also, i would like to set the PDFDocument myself, that would seem to resolve the issue? But ReaderView does not have a set method for the mDoc private property.

    Any ideas on how to increase loading performance?

    #10420 Reply

    Dr. Plug
    Moderator

    Hi Ben,

    Sorry for late reply. First, you can open PDF to another thread by using AsyncTask. like below,

    But! our SDK have using UI edit such as load display in the openFile(…). So, you should set UI again on the UI Thread(Main Thread) after openFile. So, you can set UI like below.

    Thank you,
    Dr. Plug

    #10422 Reply

    Ben

    Not true.

    At least the Android Studio does not agree with you.

    Screenshot

    Im an experienced developer, I would have used AsyncTask if it was possible.

    What do you think?

    #10423 Reply

    Ben

    As expected, im getting exceptions because of the thread when using the AsyncTask:

    E/PlugPDF: [ERROR] java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

    #10424 Reply

    Ben

    I think it is because you are calling:

    this.setPageDisplayMode(PageDisplayMode.HORIZONTAL); in openFile.

    so thus it is creating an clearing views on a background thread.

    like:

    this.loadDisplay(new HorizontalDisplay(this.mCtx));

    leading to:

    #10425 Reply

    Ben

    After forcing it to use AsyncTask, I got crazy behaviour.

    Sometimes the page would not load at all. Other times it would load but allow horizontal scrolling even though it is a single page.

    Also many flickers and other issues. It is clearly on the wrong thread.

    The only stable use is loading the ReaderView.openFile on the main thread.

    I think either something has changed or there is a fundamental problem with your readerView code and it must be rewritten.

    Are you able to share the REaderView source? Because that would not put your native libs in danger. But allow for a reimplementation by me? I need this smooth soon.

    #10427 Reply

    Ben

    Also yes i did use your example of setting the page mode in the onPostExecute.

    Also your SimpleDocumentReader uses the main thread also.

    So at this point im thinking of adding your package to my project and implementing a ReaderView myself.

    Please provide the source code for the core classes please.

    #10428 Reply

    Dr. Plug
    Moderator

    Hello Ben,

    You are right. First, openFile was contained UI edit by call the ‘setPageDisplayMode’, So you could saw the “E/PlugPDF: [ERROR] java.lang.RuntimeException”. But, that time, ReaderView has opened the document successfully. And It work fine after set the only BasePlugPDFDisplay. that task is ‘onPostExecute’ in the my previous comment.

    But if you want a source of the ReaderView. I can provide it. If you contact “support@plugpdf.com” this mail with this post link, I send the ReaderView.java file to you.

    Thank you,
    Dr. Plug

    • This reply was modified 1 year, 1 month ago by  Dr. Plug.
    #10439 Reply

    Ben

    Dear Dr. Plug,

    Well like I said, I tried your solution and I could not get it to work properly.

    So I will send you that email and address it myself. If you know this is an issue, are you planning to fix it?

    Ben

    #10440 Reply

    Ben

    Dear Dr Plug,

    I have now used the new version and it works well after your fix.

    I still would like the source of the readerview etc for the future.

    Thanks for fixing it in your release. What now remains is the fact that Android still complains about the line, but at least it works.

    Ben

Viewing 10 posts - 1 through 10 (of 13 total)
Reply To: Loading PDF data in the background instead of in the maint thread
Your information: