Tôi đang sử dụng đoạn mã sau để loại bỏ Childs trên mỗi ViewGroup:Android: Không thể phá hủy hoạt động
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();
}
}
nơi xem: R.id.RelativeLayout1 là một ListView.
Nhưng làm điều này tôi có en ngoại lệ:
E/AndroidRuntime(582): java.lang.RuntimeException: Unable to destroy activity {...}: java.lang.UnsupportedOperationException: removeAllViews() is not supported in AdapterView
Làm thế nào tôi có thể giải quyết này?
Bất kỳ ý tưởng nào tại sao AddapterView không hỗ trợ thao tác này? Tôi không thể tìm thấy bất cứ điều gì trong tham chiếu chính thức của AdapterView về nó. – r1k0
@ r1k0, Vâng, đó là bởi vì AdapterView quản lý con của nó trong nội bộ. Bạn không thể thêm/xóa chúng vì điều này có thể phá vỡ trạng thái nội bộ của nó. – inazaruk