我正在使用以下代码来删除每个视图组上的子代:
protected void onDestroy() { super.onDestroy(); this.liberarMemoria(); } public void liberarMemoria(){ imagenes.recycleBitmaps(); this.unbindDrawables(findViewById(R.id.RelativeLayout1)); System.gc(); } private void unbindDrawables(View view) { 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)); } ((ViewGroup) view).removeAllViews(); } }
视图:R.id.RelativeLayout1是ListView.
但这样做我有例外:
E/AndroidRuntime(582): java.lang.RuntimeException: Unable to destroy activity {...}: java.lang.UnsupportedOperationException: removeAllViews() is not supported in AdapterView
我该如何解决?