Skip to content

Commit

Permalink
fix: Fix a potential NPE Crash due to Mismatched Thread Lifecycle
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
facundofernandez committed Sep 16, 2024
1 parent 081372d commit 29abecd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
8 changes: 4 additions & 4 deletions android-pdf-viewer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'maven-publish'
}

group "com.github.lion1988dev"
group "com.github.GoIntegro"

android {
namespace "com.github.barteksc.pdfviewer"
Expand Down Expand Up @@ -42,15 +42,15 @@ android {

dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
api 'com.github.lion1988dev:PdfiumAndroid:1.9.4'
api 'com.github.GoIntegro:PdfiumAndroid:1.9.5'
}

publishing {
publications {
release(MavenPublication) {
groupId = 'com.github.lion1988dev'
groupId = 'com.github.GoIntegro'
artifactId = 'AndroidPdfViewer'
version = "3.2.4"
version = "3.2.5"

afterEvaluate {
from components.release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ ScrollHandle getScrollHandle() {
public PDFView(Context context, AttributeSet set) {
super(context, set);

renderingHandlerThread = new HandlerThread("PDF renderer");

if (isInEditMode()) {
return;
}
Expand Down Expand Up @@ -462,6 +460,14 @@ public void computeScroll() {
animationManager.computeFling();
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (renderingHandlerThread == null) {
renderingHandlerThread = new HandlerThread("PDF renderer");
}
}

@Override
protected void onDetachedFromWindow() {
recycle();
Expand Down Expand Up @@ -753,6 +759,10 @@ void loadComplete(PdfFile pdfFile) {

this.pdfFile = pdfFile;

if (renderingHandlerThread == null) {
renderingHandlerThread = new HandlerThread("PDF renderer");
}

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

0 comments on commit 29abecd

Please sign in to comment.