Open PDFs from In-Memory Data on Android

In most cases, it’s best to serve your PDF data from some kind of random-access storage — usually a file. Keeping your PDF data solely in memory has two major disadvantages:

  • It can quickly lead to OutOfMemoryException situations. This can happen when you don’t have full control over the size of your PDFs (e.g. when a user opens a big PDF) or when running your app on a device with less memory than anticipated.

  • An in-memory data provider can’t be retained across process recreations. By design, Android can kill your app’s process as soon as all activities of your app are in the background. Once the app comes to the foreground, your process is recreated, leaving your in-memory data provider without data.

ℹ️ Note: Due to these reasons, the previously available MemoryDataProvider was removed in PSPDFKit 3.1.1 for Android. Depending on your original usage scenario, you’re advised to use one of the other available data provider classes.