[Android] Out of memory when rotating the device multiple times

Q: We are experiencing a lot of out of memory errors when rotating the device multiple times. Since the Activity is destroyed while rotating, we get a new (quite heavy) PDFViewCtrl every time we rotate the device.

A: This happens because every time you rotate the device the activity is recreated and the current instance of PDFViewCtrl is not being finalized correctly, ie., onCreate will be called again and a new PDFViewCtrl will be instantiated, etc. One way to remedy this is to call PDFViewCtrl.destroy() on your activity:

protected void onDestroy() {

mPdfCtrl = null;

Another way to remedy this is configuring your activity to handle configuration changes. This way the control will not be recreated and it will be resized accordingly. To do this you just need to add in the manifest file the following:

For example:

android:label="@string/app_name" >

You can then override onConfigurationChanged if you need to pass this info to the ToolManager:

public void onConfigurationChanged(Configuration newConfig) {