【问题标题】:Why am I getting WIN DEATH: Window{45087aa8 com.gigabites.fortune/com.gigabites.fortune.BuildActivity paused=false} error?为什么我会收到 WIN DEATH: Window{45087aa8 com.gigabytes.fortune/com.gigabytes.fortune.Build Activity paused=false} 错误?
【发布时间】:2023-03-20 18:14:01
【问题描述】:

我环顾四周,从其他人的帖子中,我认为这个错误是因为我的活动可能超出了堆限制。我正在处理一些位图并应用了一些技术来减少我的应用程序的堆大小,例如不使用 Bitmap.createBitmap() 而是将一个小位图放大为空白位图进行修改。我还在创建的位图上使用 inPurgable 选项。这是我的代码。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i("INFO","At 2###########");
    setContentView(R.layout.landingscreen);
    Thread thread = new Thread(this);
    thread.start();

}

我的活动实现了 Runnable,这就是 run()

    public void run() {
    BitmapFactory.Options factoryOptions = new BitmapFactory.Options();
    factoryOptions.inPurgeable = true;
    factoryOptions.inInputShareable = true;
    Bitmap tempCBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.c6,factoryOptions);
    cBitmap = tempCBitmap.copy(Bitmap.Config.ARGB_8888, true);
    PrepareLines();
    Bitmap dBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dummy);
    Bitmap textLayer = Bitmap.createScaledBitmap(dBitmap, w, h, false);
    Bitmap workLayer = Bitmap.createScaledBitmap(dBitmap, w, h, false);
    canvas = new Canvas(textLayer);
    canvas.drawText(lineOne, xCenter, yCenter, paint);
    canvas.drawText(lineTwo, xCenter, yCenter+20, paint);
    canvas.drawText(lineThree, xCenter, yCenter+40, paint);

    Camera mCamera = new Camera();
    Matrix mMatrix = new Matrix();
    mCamera.save();
    mCamera.rotateY(yDegreeRotate+8);
    mCamera.getMatrix(mMatrix);
    mCamera.restore();

    mMatrix.preTranslate(-xCenter, (-yCenter)-verticalOffset);
    mMatrix.postTranslate(xCenter, yCenter+verticalOffset);
    Log.i("INFO","At before first draw ###########");


    canvas.setBitmap(workLayer);
    canvas.drawBitmap(Bitmap.createBitmap(textLayer,0,0,xCenter,h), mMatrix, paint);

    canvas.setBitmap(cBitmap);
    canvas.drawBitmap(workLayer, new Matrix(), paint);

    mMatrix = new Matrix();
    workLayer = Bitmap.createScaledBitmap(dBitmap, w, h, false);
    dBitmap = null;
    System.gc();

    mCamera.rotateY(-yDegreeRotate);
    mCamera.getMatrix(mMatrix);
    // WIN DEATH HERE
    mCamera.restore();
    // WIN DEATH HERE;
    mMatrix.preTranslate(0 , (-yCenter)-verticalOffset);
    mMatrix.postTranslate(xCenter, (yCenter)+verticalOffset);
    Log.i("INFO","At before second draw ###########");



    canvas.setBitmap(workLayer);
    canvas.drawBitmap(Bitmap.createBitmap(textLayer,xCenter,0,w-xCenter,h), mMatrix, paint);

    canvas.setBitmap(cBitmap);
    canvas.drawBitmap(workLayer, new Matrix(), paint);

    Log.i("INFO","At 20, string measures: "+paint.measureText(message));
    canvas = null;
    workLayer = null;
    textLayer = null;
    System.gc();
    makeFileAndIntent();

}

这是我的 LogCat 信息:

01-11 04:05:26.615: D/AndroidRuntime(314): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
01-11 04:05:26.615: D/AndroidRuntime(314): CheckJNI is ON
01-11 04:05:26.705: D/AndroidRuntime(314): --- registering native functions ---
01-11 04:05:27.095: D/AndroidRuntime(314): Shutting down VM
01-11 04:05:27.095: D/dalvikvm(314): Debugger has detached; object registry had 1 entries
01-11 04:05:27.105: I/AndroidRuntime(314): NOTE: attach of thread 'Binder Thread #3' failed
01-11 04:05:27.415: D/AndroidRuntime(322): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
01-11 04:05:27.415: D/AndroidRuntime(322): CheckJNI is ON
01-11 04:05:27.515: D/AndroidRuntime(322): --- registering native functions ---
01-11 04:05:27.905: I/ActivityManager(59): Force stopping package com.gigabites.fortune uid=10040
01-11 04:05:27.905: I/ActivityManager(59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.gigabites.fortune/.BuildActivity }
01-11 04:05:27.925: I/ActivityManager(59): Start proc com.gigabites.fortune for activity com.gigabites.fortune/.BuildActivity: pid=328 uid=10040 gids={1015}
01-11 04:05:27.945: W/WindowManager(59): HistoryRecord{450b8ef0 com.gigabites.fortune/.BuildActivity} failed creating starting window
01-11 04:05:27.945: W/WindowManager(59): android.view.InflateException: Binary XML file line #24: Error inflating class <unknown>
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.createView(LayoutInflater.java:513)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2165)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2220)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1407)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.internal.policy.impl.PhoneWindowManager.addStartingWindow(PhoneWindowManager.java:894)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.server.WindowManagerService$H.handleMessage(WindowManagerService.java:9007)
01-11 04:05:27.945: W/WindowManager(59):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-11 04:05:27.945: W/WindowManager(59):    at android.os.Looper.loop(Looper.java:123)
01-11 04:05:27.945: W/WindowManager(59):    at com.android.server.WindowManagerService$WMThread.run(WindowManagerService.java:570)
01-11 04:05:27.945: W/WindowManager(59): Caused by: java.lang.reflect.InvocationTargetException
01-11 04:05:27.945: W/WindowManager(59):    at android.widget.FrameLayout.<init>(FrameLayout.java:79)
01-11 04:05:27.945: W/WindowManager(59):    at java.lang.reflect.Constructor.constructNative(Native Method)
01-11 04:05:27.945: W/WindowManager(59):    at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
01-11 04:05:27.945: W/WindowManager(59):    at android.view.LayoutInflater.createView(LayoutInflater.java:500)
01-11 04:05:27.945: W/WindowManager(59):    ... 13 more
01-11 04:05:27.945: W/WindowManager(59): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x1010059 a=-1}
01-11 04:05:27.945: W/WindowManager(59):    at android.content.res.Resources.loadDrawable(Resources.java:1681)
01-11 04:05:27.945: W/WindowManager(59):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
01-11 04:05:27.945: W/WindowManager(59):    at android.widget.FrameLayout.<init>(FrameLayout.java:91)
01-11 04:05:27.945: W/WindowManager(59):    ... 17 more
01-11 04:05:27.955: D/AndroidRuntime(322): Shutting down VM
01-11 04:05:27.955: D/dalvikvm(322): Debugger has detached; object registry had 1 entries
01-11 04:05:27.975: I/dalvikvm(322): JNI: AttachCurrentThread (from ???.???)
01-11 04:05:27.975: I/AndroidRuntime(322): NOTE: attach of thread 'Binder Thread #3' failed
01-11 04:05:28.105: W/ActivityThread(328): Application com.gigabites.fortune is waiting for the debugger on port 8100...
01-11 04:05:28.135: I/System.out(328): Sending WAIT chunk
01-11 04:05:28.145: I/dalvikvm(328): Debugger is active
01-11 04:05:28.335: I/System.out(328): Debugger has connected
01-11 04:05:28.335: I/System.out(328): waiting for debugger to settle...
01-11 04:05:28.535: I/System.out(328): waiting for debugger to settle...
01-11 04:05:28.782: I/System.out(328): waiting for debugger to settle...
01-11 04:05:28.975: I/System.out(328): waiting for debugger to settle...
01-11 04:05:29.185: I/System.out(328): waiting for debugger to settle...
01-11 04:05:29.385: I/System.out(328): waiting for debugger to settle...
01-11 04:05:29.607: I/System.out(328): waiting for debugger to settle...
01-11 04:05:29.805: I/System.out(328): waiting for debugger to settle...
01-11 04:05:30.021: I/System.out(328): waiting for debugger to settle...
01-11 04:05:30.229: I/System.out(328): waiting for debugger to settle...
01-11 04:05:30.445: I/System.out(328): debugger has settled (1388)
01-11 04:05:33.015: I/INFO(328): At 2###########
01-11 04:05:34.585: I/ActivityManager(59): Displayed activity com.gigabites.fortune/.BuildActivity: 6668 ms (total 6668 ms)
01-11 04:05:37.678: I/INFO(328): At 1###########
01-11 04:05:37.785: D/dalvikvm(328): GC_EXTERNAL_ALLOC freed 1191 objects / 77104 bytes in 40ms
01-11 04:05:37.875: I/INFO(328): At 2###########
01-11 04:05:37.885: I/INFO(328): At 20, string measures: 653.0
01-11 04:05:37.925: D/dalvikvm(328): GC_EXTERNAL_ALLOC freed 360 objects / 16904 bytes in 35ms
01-11 04:05:37.985: D/dalvikvm(328): GC_EXTERNAL_ALLOC freed 47 objects / 1776 bytes in 35ms
01-11 04:05:38.055: I/INFO(328): At before first draw ###########
01-11 04:05:38.135: D/dalvikvm(328): GC_EXTERNAL_ALLOC freed 15 objects / 632 bytes in 30ms
01-11 04:05:38.196: D/dalvikvm(328): GC_EXPLICIT freed 12 objects / 424 bytes in 31ms
01-11 04:05:38.345: I/DEBUG(31): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-11 04:05:38.345: I/DEBUG(31): Build fingerprint: 'generic/google_sdk/generic/:2.2/FRF91/43546:eng/test-keys'
01-11 04:05:38.345: I/DEBUG(31): pid: 328, tid: 335  >>> com.gigabites.fortune <<<
01-11 04:05:38.345: I/DEBUG(31): signal 11 (SIGSEGV), fault addr deadbaad
01-11 04:05:38.345: I/DEBUG(31):  r0 00000000  r1 0000000c  r2 00000027  r3 00000000
01-11 04:05:38.345: I/DEBUG(31):  r4 00000000  r5 deadbaad  r6 00001728  r7 00000000
01-11 04:05:38.345: I/DEBUG(31):  r8 46d00d10  r9 4185ef74  10 002404e8  fp 4185ef70
01-11 04:05:38.345: I/DEBUG(31):  ip ffffffff  sp 46d00c80  lr afd154c5  pc afd11dc4  cpsr 40000030
01-11 04:05:38.415: I/DEBUG(31):          #00  pc 00011dc4  /system/lib/libc.so
01-11 04:05:38.415: I/DEBUG(31):          #01  pc 0000be1c  /system/lib/libc.so
01-11 04:05:38.415: I/DEBUG(31): code around pc:
01-11 04:05:38.415: I/DEBUG(31): afd11da4 1c2bd00b 2d00682d e026d1fb 2b0068db 
01-11 04:05:38.415: I/DEBUG(31): afd11db4 4e17d003 51a02001 4d164798 24002227 
01-11 04:05:38.415: I/DEBUG(31): afd11dc4 f7fb702a 2106ee14 ef10f7fc 05592380 
01-11 04:05:38.415: I/DEBUG(31): afd11dd4 6091aa01 1c116054 94012006 eab6f7fc 
01-11 04:05:38.415: I/DEBUG(31): afd11de4 2200a905 f7fc2002 f7fbeac2 2106ee00 
01-11 04:05:38.415: I/DEBUG(31): code around lr:
01-11 04:05:38.415: I/DEBUG(31): afd154a4 b0834a0d 589c447b 26009001 686768a5 
01-11 04:05:38.415: I/DEBUG(31): afd154b4 220ce008 2b005eab 1c28d003 47889901 
01-11 04:05:38.415: I/DEBUG(31): afd154c4 35544306 d5f43f01 2c006824 b003d1ee 
01-11 04:05:38.415: I/DEBUG(31): afd154d4 bdf01c30 0002ae7c 000000d4 1c0fb5f0 
01-11 04:05:38.415: I/DEBUG(31): afd154e4 43551c3d a904b087 1c16ac01 604d9004 
01-11 04:05:38.415: I/DEBUG(31): stack:
01-11 04:05:38.415: I/DEBUG(31):     46d00c40  00000015  
01-11 04:05:38.415: I/DEBUG(31):     46d00c44  afd1453b  /system/lib/libc.so
01-11 04:05:38.415: I/DEBUG(31):     46d00c48  afd405a0  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c4c  afd4054c  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c50  00000000  
01-11 04:05:38.426: I/DEBUG(31):     46d00c54  afd154c5  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c58  00000000  
01-11 04:05:38.426: I/DEBUG(31):     46d00c5c  afd1450d  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c60  afd41724  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c64  afd40328  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c68  00000000  
01-11 04:05:38.426: I/DEBUG(31):     46d00c6c  00001728  
01-11 04:05:38.426: I/DEBUG(31):     46d00c70  00000000  
01-11 04:05:38.426: I/DEBUG(31):     46d00c74  afd147ab  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c78  df002777  
01-11 04:05:38.426: I/DEBUG(31):     46d00c7c  e3a070ad  
01-11 04:05:38.426: I/DEBUG(31): #00 46d00c80  8086caa4  /system/lib/libdvm.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c84  80870eea  /system/lib/libdvm.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c88  afd418dc  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c8c  afd10510  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c90  afd40328  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c94  fffffbdf  
01-11 04:05:38.426: I/DEBUG(31):     46d00c98  afd40328  /system/lib/libc.so
01-11 04:05:38.426: I/DEBUG(31):     46d00c9c  afd41724  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00ca0  0000a000  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00ca4  afd0be21  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31): #01 46d00ca8  afd40328  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cac  afd0be21  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cb0  418cb358  /dev/ashmem/dalvik-LinearAlloc (deleted)
01-11 04:05:38.435: I/DEBUG(31):     46d00cb4  80846dad  /system/lib/libdvm.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cb8  00119ab8  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cbc  00234078  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cc0  44ef45a8  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
01-11 04:05:38.435: I/DEBUG(31):     46d00cc4  8083d9b9  /system/lib/libdvm.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cc8  000013fc  
01-11 04:05:38.435: I/DEBUG(31):     46d00ccc  00234608  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cd0  44ef45a8  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
01-11 04:05:38.435: I/DEBUG(31):     46d00cd4  00119ab8  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cd8  afd417e0  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00cdc  42c3d5f6  /data/dalvik-cache/system@framework@framework.jar@classes.dex
01-11 04:05:38.435: I/DEBUG(31):     46d00ce0  4185ef7c  
01-11 04:05:38.435: I/DEBUG(31):     46d00ce4  afd0cd81  /system/lib/libc.so
01-11 04:05:38.435: I/DEBUG(31):     46d00ce8  00119ab8  [heap]
01-11 04:05:38.435: I/DEBUG(31):     46d00cec  afc008e3  /system/lib/libstdc++.so
01-11 04:05:38.855: I/BootReceiver(59): Copying /data/tombstones/tombstone_08 to DropBox (SYSTEM_TOMBSTONE)
01-11 04:05:38.875: D/Zygote(33): Process 328 terminated by signal (11)
01-11 04:05:38.955: D/dalvikvm(59): GC_FOR_MALLOC freed 2276 objects / 507544 bytes in 99ms
01-11 04:05:38.955: I/ActivityManager(59): Process com.gigabites.fortune (pid 328) has died.
01-11 04:05:38.965: I/WindowManager(59): WIN DEATH: Window{45087aa8 com.gigabites.fortune/com.gigabites.fortune.BuildActivity paused=false}
01-11 04:05:38.975: I/UsageStats(59): Unexpected resume of com.android.launcher while already resumed in com.gigabites.fortune
01-11 04:05:39.055: D/dalvikvm(59): GC_FOR_MALLOC freed 512 objects / 159856 bytes in 66ms
01-11 04:05:39.156: W/InputManagerService(59): Got RemoteException sending setActive(false) notification to pid 328 uid 10040

我的 android 模拟器堆大小是 24 当我在充满活力的银河系上运行它时,一切似乎都运行良好。

这是我用于登陆屏幕布局的 XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" android:background="@color/maroon" android:gravity="center">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="@drawable/darkred_maroon_gradient" >

        <TextView
                    android:id="@+id/titlebar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="12sp"
                    android:textAppearance="?android:attr/textAppearanceSmall" android:text="@string/app_name" android:background="@drawable/darkred_maroon_gradient" android:paddingLeft="5dp" android:textColor="@color/yellow" android:typeface="monospace" android:gravity="left|center_vertical"/>
        <TextView
                    android:id="@+id/titlebar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="12sp"
                    android:textAppearance="?android:attr/textAppearanceSmall" android:text="GiGA BiTES" android:gravity="right|center_vertical" android:paddingRight="5dp" android:textColor="@color/yellow" android:typeface="monospace"/>
    </LinearLayout>

    <TableLayout
        android:id="@+id/tableLayout1"
        android:weightSum="2"
        android:layout_width="match_parent"

        android:layout_height="match_parent" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_weight="1"
            android:layout_height="wrap_content" android:weightSum="2">

            <RelativeLayout 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" android:layout_weight="1"
                android:gravity="center" android:layout_gravity="center">

                <ImageView
                    android:id="@+id/ncview"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:src="@drawable/newcicon" android:scaleType="center" android:layout_centerHorizontal="true" android:paddingTop="3dp"/>
                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/newc"
                    android:onClick="onClick"
                    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_centerInParent="true" android:textColor="@color/yellow"/>
            </RelativeLayout>
            <RelativeLayout 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" android:layout_weight="1" android:gravity="center">
                <ImageView
                    android:id="@+id/scview"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:src="@drawable/sendcicon" android:scaleType="center" android:layout_centerHorizontal="true"/>

                <TextView
                    android:onClick="onClick"
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/sendc" 
                    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_centerInParent="true" android:textColor="@color/yellow"/>

            </RelativeLayout>

        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_weight="1"
            android:weightSum="2">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:orientation="vertical" android:layout_weight="1" android:gravity="center" android:layout_gravity="bottom">
                <ImageView
                    android:id="@+id/ctview"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:scaleType="center"
                    android:src="@drawable/cticon" android:layout_centerHorizontal="true" android:paddingTop="25dp"/>
                <TextView
                    android:onClick="onClick"
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/buytokens" 
                    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_gravity="bottom|center_horizontal" android:layout_centerInParent="true" android:gravity="center" android:textColor="@color/yellow"/>
            </RelativeLayout>
            <RelativeLayout 
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:orientation="vertical" android:layout_weight="1" android:gravity="center">
                <ImageView
                    android:id="@+id/hview"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:scaleType="center"
                    android:src="@drawable/helpicon" android:layout_centerHorizontal="true"/>
                <TextView
                    android:id="@+id/textView4"
                    android:onClick="onClick"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/help"
                    android:textAppearance="?android:attr/textAppearanceLarge" android:layout_centerInParent="true" android:textColor="@color/yellow"/>
            </RelativeLayout>


        </TableRow>

    </TableLayout>

</LinearLayout>

另外,我在堆大小为 32 的模拟器上尝试了这个,但仍然遇到同样的问题。

更新:我现在尝试在 AsyncTask 对象的 doInBackground 中创建此位图,但遇到了同样的问题

另外,我想指出,我现在正在从 drawable-nodpi 文件夹加载资源,这样模拟器就不会进行任何调整大小并且仍然存在问题。

【问题讨论】:

  • 你能贴一下landingscreen.xml吗?
  • 那里,我发布了.xml

标签: android eclipse bitmap heap-memory


【解决方案1】:

Android 中的位图在垃圾收集方面存在问题。 Java Bitmap 对象只是一个处理对象的真正工作的本地对象的句柄。本机对象存储在 Java 堆之外,因此不被垃圾收集器处理。

一旦Java Bitmap 对象被垃圾回收,它将释放本机对象。然而,Java 对象比位图数据小得多,因此如果您继续创建新的 Java 位图实例,则本机堆将在调用 GC 之前填满,即使您释放对对象的引用也是如此。由于当 Java 堆太满时,本机堆对 Java 堆一无所知,因此它不会调用 GC,它只会简单地爆炸。

避免这种情况的关键是在使用完 Java 对象后调用 Bitmap.recycle() 来释放本机对象,就像使用 C++ 时一样。不幸的是,Java 不支持析构函数或智能指针,所以你只需要依赖程序员的纪律。

在您的情况下,对 recycle() 的调用是由相机进行的,所以这就是您的修复工作的原因。

【讨论】:

  • 在 Pre-Honeycomb 中确实如此。不再以这种方式处理位图内存。
  • 是否需要详细说明蜂窝后的内存?
  • 蜂窝后,位图内存分配在Java堆中。观看此演讲:youtube.com/watch?v=_CruQY55HOk
【解决方案2】:

我收到错误是因为我没有平衡每个 Camera.save() 调用和 Camera.restore() 调用。

【讨论】:

    【解决方案3】:

    当我遇到大堆问题时,我去模拟器定义并更改了那里的内存大小。我记得默认内存非常小。你的 32 也不算多。为什么要这么限制自己?

    【讨论】:

    • 我将其限制为 24,因为这样它将支持更多的手机。我这样想对吗?所以现在,如果我要发布我的应用程序,它将无法在堆大小为 24 的手机上运行。另外,我认为存储 3 个位图不应该使用那么多堆内存。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 2022-01-23
    • 2020-11-05
    • 2018-06-22
    • 2020-01-12
    • 2016-01-01
    相关资源
    最近更新 更多