AndroidPdfViewer
AndroidPdfViewer copied to clipboard
When pdf is Loaded again from background
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.HandlerThread.isAlive()' on a null object reference
if (!renderingHandlerThread.isAlive()) { renderingHandlerThread.start(); }
same here
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.
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 please share example code on how to use flag.
@ssindher11 Please share example to understand it better Thanks in Advance
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?
Still no solution for this ?
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. */
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() }
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)
Have you found any solution for this ? I am facing the exact issue.
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.
Can anyone has solution for this issue?