Я пытаюсь сделать Double View пейджер и я переопределить destroyItem
функции от моего PagerAdapter так же, как в коде ниже:unbindDrawables в PagerAdapter Android Lollipop не работает
@Override
public void destroyItem(ViewGroup container, int position, Object object)
{
container.removeView((View) object);
unbindDrawables((View) object);
System.gc();
object = null;
}
protected void unbindDrawables(View view)
{
if (view instanceof ImageView)
{
Drawable drawable = ((ImageView) view).getDrawable();
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
Bitmap bitmap = bitmapDrawable.getBitmap();
bitmap.recycle();
}
ImageWorker.cancelWork(((ImageView) view));
((ImageView) view).setImageResource(0);
((ImageView) view).setImageDrawable(null);
}
if (view.getBackground() != null)
{
view.getBackground().setCallback(null);
}
if (view instanceof ViewGroup)
{
for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++)
{
unbindDrawables(((ViewGroup) view).getChildAt(i));
}
if (!(view instanceof AdapterView<?>))
{
((ViewGroup) view).removeAllViews();
}
//((ViewGroup) view).removeAllViews();
}
}
Все нормально на Android KitKat, Jelly Bean , даже на Gingerbread и Ice Cream Sandwich, но когда я пытаюсь проверить свое приложение на API 21 и выше, у меня есть исключение из памяти. Когда я отлаживаю свой код, я не вижу проблемы. Может кто-нибудь мне помочь ? Благодарю.