Skip to content

Commit 29abecd

Browse files
fix: Fix a potential NPE Crash due to Mismatched Thread Lifecycle
- the thread creation and recycling was not being handled symmetrically - this fix is based off of these two PR: DImuthuUpe#824 and mhiew#2 ref: DImuthuUpe/AndroidPdfViewer@41f912e
1 parent 081372d commit 29abecd

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

android-pdf-viewer/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id 'maven-publish'
44
}
55

6-
group "com.github.lion1988dev"
6+
group "com.github.GoIntegro"
77

88
android {
99
namespace "com.github.barteksc.pdfviewer"
@@ -42,15 +42,15 @@ android {
4242

4343
dependencies {
4444
implementation 'androidx.appcompat:appcompat:1.6.1'
45-
api 'com.github.lion1988dev:PdfiumAndroid:1.9.4'
45+
api 'com.github.GoIntegro:PdfiumAndroid:1.9.5'
4646
}
4747

4848
publishing {
4949
publications {
5050
release(MavenPublication) {
51-
groupId = 'com.github.lion1988dev'
51+
groupId = 'com.github.GoIntegro'
5252
artifactId = 'AndroidPdfViewer'
53-
version = "3.2.4"
53+
version = "3.2.5"
5454

5555
afterEvaluate {
5656
from components.release

android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,6 @@ ScrollHandle getScrollHandle() {
245245
public PDFView(Context context, AttributeSet set) {
246246
super(context, set);
247247

248-
renderingHandlerThread = new HandlerThread("PDF renderer");
249-
250248
if (isInEditMode()) {
251249
return;
252250
}
@@ -462,6 +460,14 @@ public void computeScroll() {
462460
animationManager.computeFling();
463461
}
464462

463+
@Override
464+
protected void onAttachedToWindow() {
465+
super.onAttachedToWindow();
466+
if (renderingHandlerThread == null) {
467+
renderingHandlerThread = new HandlerThread("PDF renderer");
468+
}
469+
}
470+
465471
@Override
466472
protected void onDetachedFromWindow() {
467473
recycle();
@@ -753,6 +759,10 @@ void loadComplete(PdfFile pdfFile) {
753759

754760
this.pdfFile = pdfFile;
755761

762+
if (renderingHandlerThread == null) {
763+
renderingHandlerThread = new HandlerThread("PDF renderer");
764+
}
765+
756766
if (!renderingHandlerThread.isAlive()) {
757767
renderingHandlerThread.start();
758768
}

0 commit comments

Comments
 (0)