gpt4 book ai didi

android - 方向更改时出现内存不足错误

转载 作者:行者123 更新时间:2023-11-29 18:04:59 25 4
gpt4 key购买 nike

我有一个使用 osmdroid mapactivity 的应用。

每次屏幕方向堆大小增加时,在几次方向更改后,我都会收到以下错误:

12-12 00:53:08.990: E/dalvikvm-heap(6712): Out of memory on a 262160-byte allocation.
12-12 00:53:08.990: I/dalvikvm(6712): "filesystem" prio=5 tid=46 RUNNABLE
12-12 00:53:08.990: I/dalvikvm(6712): | group="main" sCount=0 dsCount=0 obj=0x43057e08 self=0x571583c8
12-12 00:53:08.990: I/dalvikvm(6712): | sysTid=8674 nice=0 sched=0/0 cgrp=apps handle=1487255264
12-12 00:53:08.990: I/dalvikvm(6712): | schedstat=( 298265664 165380214 301 ) utm=25 stm=4 core=0
12-12 00:53:08.990: I/dalvikvm(6712): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
12-12 00:53:08.995: I/dalvikvm(6712): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
12-12 00:53:08.995: I/dalvikvm(6712): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:389)
12-12 00:53:08.995: I/dalvikvm(6712): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:449)
12-12 00:53:08.995: I/dalvikvm(6712): at org.osmdroid.tileprovider.tilesource.BitmapTileSourceBase.getDrawable(BitmapTileSourceBase.java:93)
12-12 00:53:08.995: I/dalvikvm(6712): at org.osmdroid.tileprovider.modules.MapTileFilesystemProvider$TileLoader.loadTile(MapTileFilesystemProvider.java:142)
12-12 00:53:08.995: I/dalvikvm(6712): at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$TileLoader.run(MapTileModuleProviderBase.java:241)
12-12 00:53:08.995: I/dalvikvm(6712): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
12-12 00:53:08.995: I/dalvikvm(6712): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
12-12 00:53:08.995: I/dalvikvm(6712): at java.lang.Thread.run(Thread.java:856)
12-12 00:53:09.020: I/dalvikvm-heap(6712): Clamp target GC heap from 64.436MB to 64.000MB
12-12 00:53:09.050: I/dalvikvm-heap(6712): Forcing collection of SoftReferences for 262160-byte allocation
12-12 00:53:09.095: I/dalvikvm-heap(6712): Clamp target GC heap from 64.436MB to 64.000MB

我有一个包含两个 fragment 的 Activity ,这两个 fragment 都扩展了一个初始化 MapActivity 的抽象 fragment 。

我看了很多有同样问题的人的帖子。我最终在抽象 fragment 中实现了以下内容:

    @Override
public void onDestroyView() {
super.onDestroyView();

unbindDrawables(con.findViewById(R.id.main_layout));
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();
}
}

这是我的 onCreateView,它初始化了 con:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
con = container;
return inflater.inflate(R.layout.main_fragment,container, false);
}

我不确定我还能做什么。

谁能帮我解决这个问题?

谢谢

最佳答案

尝试自己处理屏幕旋转,将以下代码添加到 Activity 中

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

并将以下内容添加到 list 文件中的 Activity 标签中

android:configChanges="方向|keyboardHidden|screenSize"

关于android - 方向更改时出现内存不足错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13831101/

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