我刚刚在我正在从事的项目中遇到了同样的问题。事实证明,我在尝试实例化 Activity 时加载了大量图像和声音,导致应用程序内存不足。您的程序是否使用大量内存密集型资产?你能完全减小它们的尺寸吗?
在我的例子中,LogCat 在行前有一个绿色的堆栈跟踪(INFO 级日志记录)Fatal signal 11 (SIGSEGV)
。堆栈跟踪是OutOfMemoryException
在应用程序为Activity
我启动时加载资产的时候。所以我拉起我的drawables(我的程序有很多),编辑它们以减小它们的文件大小,然后再试一次。虫子消失了。你可以看看你的 LogCat 输出是否和我的一样,看看你是否有类似的问题:
01-15 05:20:40.462: E/dalvikvm-heap(4513): Out of memory on a 3145744-byte allocation.
01-15 05:20:40.462: I/dalvikvm(4513): "main" prio=5 tid=1 RUNNABLE
01-15 05:20:40.462: I/dalvikvm(4513): | group="main" sCount=0 dsCount=0 obj=0x4158b6a0 self=0x41001a60
01-15 05:20:40.462: I/dalvikvm(4513): | sysTid=4513 nice=0 sched=0/0 cgrp=apps handle=1074673744
01-15 05:20:40.462: I/dalvikvm(4513): | schedstat=( 0 0 0 ) utm=41 stm=20 core=1
01-15 05:20:40.462: I/dalvikvm(4513): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
01-15 05:20:40.462: I/dalvikvm(4513): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:592)
01-15 05:20:40.462: I/dalvikvm(4513): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:445)
01-15 05:20:40.462: I/dalvikvm(4513): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
01-15 05:20:40.462: I/dalvikvm(4513): at android.content.res.Resources.loadDrawable(Resources.java:1963)
01-15 05:20:40.462: I/dalvikvm(4513): at android.content.res.Resources.getDrawable(Resources.java:672)
01-15 05:20:40.462: I/dalvikvm(4513): at com.kbi.speeddraw.lite.game.drawables.character.ExplodingCharacterDrawable.<init>(ExplodingCharacterDrawable.java:27)
<!-- snip -->
01-15 05:20:40.462: I/dalvikvm(4513): at com.kbi.gameengine.api.gameactivity.GameActivity.onCreate(GameActivity.java:80)
01-15 05:20:40.472: I/dalvikvm(4513): at android.app.Activity.performCreate(Activity.java:5048)
01-15 05:20:40.472: I/dalvikvm(4513): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-15 05:20:40.472: I/dalvikvm(4513): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2052)
01-15 05:20:40.472: I/dalvikvm(4513): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
01-15 05:20:40.472: I/dalvikvm(4513): at android.app.ActivityThread.access$700(ActivityThread.java:139)
01-15 05:20:40.472: I/dalvikvm(4513): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
01-15 05:20:40.472: I/dalvikvm(4513): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 05:20:40.472: I/dalvikvm(4513): at android.os.Looper.loop(Looper.java:137)
01-15 05:20:40.472: I/dalvikvm(4513): at android.app.ActivityThread.main(ActivityThread.java:4918)
01-15 05:20:40.472: I/dalvikvm(4513): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 05:20:40.472: I/dalvikvm(4513): at java.lang.reflect.Method.invoke(Method.java:511)
01-15 05:20:40.472: I/dalvikvm(4513): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
01-15 05:20:40.472: I/dalvikvm(4513): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
01-15 05:20:40.472: I/dalvikvm(4513): at dalvik.system.NativeStart.main(Native Method)
01-15 05:20:40.472: A/libc(4513): Fatal signal 11 (SIGSEGV) at 0x00000be0 (code=1), thread 4513 (.speeddraw.lite)
01-15 05:20:40.472: A/libc(4513): Fatal signal 11 (SIGSEGV) at 0x00180500 (code=1), thread 4527 (.speeddraw.lite)