afreakyelf / Pdf-Viewer

A Lightweight PDF Viewer Android library which only occupies around 80kb while most of the Pdf viewer occupies up to 16MB space.
https://afreakyelf.github.io/Pdf-Viewer/
MIT License
692 stars 150 forks source link

[BUG] java.lang.IllegalStateException: Current page not closed #109

Closed VortanaSay01 closed 3 months ago

VortanaSay01 commented 4 months ago

📝 Describe the Bug

App crash when repeat these these steps: open pdf via pdfViewerActivity then back from activity.

📖 Library Version

🚶 Steps to Reproduce

Please follow these steps to reproduce the issue:

  1. start pdfViewerActivity with launchPdfFromUrl
  2. click on link to open pdf
  3. click back
  4. click on link to open pdf again
  5. click back
  6. repeat these two steps
  7. App crash

🤔 Expected Behavior

App should open pdf and no crash

🖼️ Screenshots/Videos

If applicable, add screenshots or videos to help explain your problem.

📱 Smartphone Info:

💻 Code Snippets

startActivity( PdfViewerActivity.launchPdfFromUrl( context = this, pdfUrl = uri.toString(), pdfTitle = "", saveTo = saveTo.ASK_EVERYTIME, enableDownload = true ) )

📜 Log Output/Stack Trace

Caused by: java.lang.IllegalStateException: Current page not closed at android.graphics.pdf.PdfRenderer.throwIfPageOpened(PdfRenderer.java:279) at android.graphics.pdf.PdfRenderer.close(PdfRenderer.java:191) at com.rajat.pdfviewer.PdfRendererCore.closePdfRender(PdfRendererCore.kt:175) at com.rajat.pdfviewer.PdfRendererView.closePdfRender(PdfRendererView.kt:242) at com.rajat.pdfviewer.PdfViewerActivity.onDestroy(PdfViewerActivity.kt:507) at android.app.Activity.performDestroy(Activity.java:8571) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1364) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5937) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5995)  at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:47)  at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)  at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2438)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loopOnce(Looper.java:226)  at android.os.Looper.loop(Looper.java:313)  at android.app.ActivityThread.main(ActivityThread.java:8663)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) 

💬 Additional Context

Add any other context about the problem here. Mention if the issue is consistent, specific scenarios where the bug occurs, etc.


github-actions[bot] commented 4 months ago

Thank you for creating your first issue. We appreciate your help in making this project better. We will look into it, and get back to you soon.

sumit-joshi28 commented 4 months ago

I had reported one crash similar to your case, and this issue still exists but it is closed without a fix or solution.

https://github.com/afreakyelf/Pdf-Viewer/issues/100

ArisonRaik commented 3 months ago

I noticed this bug when you close the PDF while displaying a page with a huge image, like the cover of a book

afreakyelf commented 3 months ago

Hey, Can you share what device you are using? It could be a performance-related issue, as I could not reproduce it.

Thanks

ArisonRaik commented 3 months ago

I tested on an Asus M2 and on a Samsung A1, both had this same issue

VortanaSay01 commented 3 months ago

I saw the issue in Samsung Galaxy. Android 12. I also noticed the issue when open pdf before it load or quickly press back to previous screen.

afreakyelf commented 3 months ago

Hi, The Above issue has been fixed in new release. https://github.com/afreakyelf/Pdf-Viewer/releases/tag/v2.1.0

Please migrate to Maven central. More here: https://github.com/afreakyelf/Pdf-Viewer/releases/tag/v2.1.0

Thank you for using the library. Please reopen/raise a new issue if you still face this error.

Join our discord for more updates!