我試圖讓雙查看傳呼機,我從我的PagerAdapter代碼重寫destroyItem
功能就像波紋管: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();
}
}
一切OK Android KitKat上,果凍豆,甚至在薑餅和冰淇淋三明治上,但是當我嘗試在API 21和更高版本上測試我的應用程序時,我有內存異常。當我調試我的代碼時,我看不到問題。誰能幫我 ?謝謝。