gpt4 book ai didi

Android:无法销毁 Activity

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:58:25 29 4
gpt4 key购买 nike

我正在使用以下代码删除每个 View 组中的 child :

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();
}
}

其中 View :R.id.RelativeLayout1 是一个 ListView。

但是这样做我有一个异常(exception):

E/AndroidRuntime(582): java.lang.RuntimeException: Unable to destroy activity {...}: java.lang.UnsupportedOperationException: removeAllViews() is not supported in AdapterView

我该如何解决这个问题?

最佳答案

嗯,错误日志几乎解释了它:不要在 AdapterView 上调用 removeAllViews()。并且您的代码在某个时刻遇到了 ViewGroup,它也是 AdapterView

只需使用 instanceof 检查或使用 try/catch 包装器处理异常即可排除这种情况。

关于Android:无法销毁 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8405475/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com