I have seen various issues akin to this on StackOverflow and elsewhere, but none of those solutions seem to be solving my problem, which is as follows:
I have a ViewPager with a simple PagerAdapter. Each "page" has an XML layout associated with it that contains at least one TextView, one ImageView, and sometimes another TextView. The images associated with the ImageViews are generally 1000px in one dimension and less in the other, but they are 8-bit indexed gifs, so none of them is much larger than 20kB. I set them as Drawables, and they scale down appropriately to fit the space allocated to them.
There are only 6 pages. When I launch the activity, it works fine, and I can even flip to the last page, but if I flip all the way to the right and then all the way back to the left, I get an OutOfMemoryError. This doesn't make sense to me because I thought the ViewPager was supposed to destroy the pages more than 1 screen away, and I am handling destroyItem() as suggested in various other places.
Here is the code for the PagerAdapter:
package doop.doop.dedoop;
import doop.doop.dedoop.R.layout;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
public class HelpPagerAdapter extends PagerAdapter{
private Context applicationContext;
private Context activityContext;
public HelpPagerAdapter(Context appContext, Context activContext){
applicationContext = appContext;
activityContext = activContext;
}
public int getCount() {
return 6;
}
public Object instantiateItem(ViewGroup collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
int ivId = 0;