diff --git a/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java b/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java index b8374721..0950c5a6 100644 --- a/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java +++ b/android-pdf-viewer/src/main/java/com/github/barteksc/pdfviewer/PDFView.java @@ -245,8 +245,6 @@ ScrollHandle getScrollHandle() { public PDFView(Context context, AttributeSet set) { super(context, set); - renderingHandlerThread = new HandlerThread("PDF renderer"); - if (isInEditMode()) { return; } @@ -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(); @@ -753,6 +759,10 @@ void loadComplete(PdfFile pdfFile) { this.pdfFile = pdfFile; + if (renderingHandlerThread == null) { + return; + } + if (!renderingHandlerThread.isAlive()) { renderingHandlerThread.start(); }