AndroidPdfViewer icon indicating copy to clipboard operation
AndroidPdfViewer copied to clipboard

When pdf is Loaded again from background

Open ethemsulan opened this issue 5 years ago • 14 comments

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.HandlerThread.isAlive()' on a null object reference

if (!renderingHandlerThread.isAlive()) { renderingHandlerThread.start(); }

ethemsulan avatar Oct 19 '19 17:10 ethemsulan

same here

grizzly avatar Nov 25 '19 12:11 grizzly

I also encountered this issue. The loadComplete method should probably check for renderingHandlerThread != null before handling the callback, because the renderingHandlerThread is set to null when the view is detached from the window.

rvanderlinden avatar Jan 09 '20 14:01 rvanderlinden

Until it is fixed, you can use a flag variable which is set to false when you leave the activity. And load the PDF only when the flag is true.

ssindher11 avatar Feb 05 '20 11:02 ssindher11

@ssindher11 please share example code on how to use flag.

StonedNinjaa avatar May 24 '20 17:05 StonedNinjaa

@ssindher11 Please share example to understand it better Thanks in Advance

rohit75 avatar Aug 04 '20 10:08 rohit75

I cant even reproduce this issue but the crash events on firebase are high. When activity starts and PDF is loaded In PDFView.java loadComplete is called but when i switch the app to background and then it comes to foreground again this method is not even called. Any help how to reproduce this issue so that i can apply a proper fix?

NayabSarfraz avatar Feb 12 '21 04:02 NayabSarfraz

Still no solution for this ?

passmanagerapp avatar Jun 09 '21 18:06 passmanagerapp

I Fixed it like this

 if (!isDestroyed) {
            binding.pdfView.fromFile(file)
                .onPageError { page, _ ->
                    showToast("Error at page: $page")
                }.onError { error ->
                    error.message?.let {
                        showToast(it)
                    }

                }
                .load()
        }

/** * isDestroyed * Returns true if the final {@link #onDestroy()} call has been made * on the Activity, so this instance is now dead. */

MohamedAbdelrazek avatar Jun 19 '21 13:06 MohamedAbdelrazek

Instead of using Flag like stuff I recommend this approach. withContext(Dispatchers.Main) { // I assume that you were working with some spendable job if ([email protected]) { // Apply this condition to prevent that crash dataBinding!!.pdfView.fromStream( stream ) .load() updateSelection(it.data) } client.dispatcher.executorService.shutdown() }

AliUsman3233 avatar Jan 13 '22 11:01 AliUsman3233

I also encountered this issue 1at Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.HandlerThread.isAlive()' on a null object reference 2at com.github.barteksc.pdfviewer.PDFView.a(PDFView.java:756) 3at com.github.barteksc.pdfviewer.c.a(DecodingAsyncTask.java:80) 4at com.github.barteksc.pdfviewer.c.onPostExecute(DecodingAsyncTask.java:27)

jiantao88 avatar Feb 08 '22 02:02 jiantao88

Have you found any solution for this ? I am facing the exact issue.

saurabh-drishti avatar Mar 05 '22 10:03 saurabh-drishti

I Fixed it like this

 if (!isDestroyed) {
            binding.pdfView.fromFile(file)
                .onPageError { page, _ ->
                    showToast("Error at page: $page")
                }.onError { error ->
                    error.message?.let {
                        showToast(it)
                    }

                }
                .load()
        }

/** * isDestroyed * Returns true if the final {@link #onDestroy()} call has been made * on the Activity, so this instance is now dead. */

this worked for me... thanks.

sahilk01 avatar May 07 '22 19:05 sahilk01

Can anyone has solution for this issue?

Shvet avatar Nov 23 '23 13:11 Shvet