Android应用会在方向更改时停止而不会出错

时间:2011-08-24 17:48:30

标签: android

我正在开发一款使用Google地图API的应用。我开发了两种不同的布局来处理两种类型的方向(纵向和横向)。一切都很好,除了我有一个非常奇怪的错误。

有时,当我将手机从纵向翻转到横向或反之亦然时,应用程序将会关闭。屏幕上没有可见的错误。 Logcat中没有抛出任何异常。这几乎就像我的应用只是调用finish()并退出(这不是程序中的任何地方)。我还没有试图保留任何旋转状态,所以现在应用程序有效地重新启动。有时,在发生这种情况之前我会翻转50次,有时两次。

我唯一能找到的就是这个问题: Android Screen Orientation Change Causes App To Quit

它根本没有帮助。

但是,正常日志中会弹出一条大信息。

I/DEBUG   (24223): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (24223): Build fingerprint: 'sprint/htc_supersonic/supersonic/supersonic:2.2/FRF91/294884:user/release-keys'
I/DEBUG   (24223): pid: 24329, tid: 24329  >>> ---name of my package--- <<<
I/DEBUG   (24223): signal 11 (SIGSEGV), fault addr 00000000
I/DEBUG   (24223):  r0 005003d0  r1 00000000  r2 00000000  r3 005003f4
I/DEBUG   (24223):  r4 005003d0  r5 00000000  r6 00000000  r7 00000000
I/DEBUG   (24223):  r8 be8ae130  r9 4187369c  10 41873688  fp be8ae478
I/DEBUG   (24223):  ip 005003d0  sp be8adef8  lr 00000000  pc ab14b0e4  cpsr 60000010
I/DEBUG   (24223):  d0  6472656767756265  d1  6f6c6c6120737562
I/DEBUG   (24223):  d2  6f6f74206e6f6979  d3  6620656772616c74
I/DEBUG   (24223):  d4  0000000044340000  d5  4448000044340000
I/DEBUG   (24223):  d6  3fc000003fc00000  d7  4080000080000000
I/DEBUG   (24223):  d8  000002d044961000  d9  0000000000000000
I/DEBUG   (24223):  d10 0000000000000000  d11 0000000000000000
I/DEBUG   (24223):  d12 0000000000000000  d13 0000000000000000
I/DEBUG   (24223):  d14 0000000000000000  d15 0000000000000000
I/DEBUG   (24223):  d16 00000000460b1918  d17 bff0000000000000
I/DEBUG   (24223):  d18 3ff0000000000000  d19 0000000000000000
I/DEBUG   (24223):  d20 0000000000000000  d21 0000000000000000
I/DEBUG   (24223):  d22 3ff0000000000000  d23 0000000000000000
I/DEBUG   (24223):  d24 3ff0000000000000  d25 0000000000000000
I/DEBUG   (24223):  d26 0000000000000000  d27 0000000000000000
I/DEBUG   (24223):  d28 0008000a00050002  d29 0003000b000d0009
I/DEBUG   (24223):  d30 001f001f001f001f  d31 001f001f001f001f
I/DEBUG   (24223):  scr 68000012
I/DEBUG   (24223):
I/DEBUG   (24223):          #00  pc 0004b0e4  /system/lib/libskia.so
I/DEBUG   (24223):          #01  pc 0004b1a8  /system/lib/libskia.so
I/DEBUG   (24223):          #02  pc 0006896c  /system/lib/libskia.so
I/DEBUG   (24223):          #03  pc 0006434c  /system/lib/libskia.so
I/DEBUG   (24223):          #04  pc 0004f7c0  /system/lib/libandroid_runtime.so
I/DEBUG   (24223):
I/DEBUG   (24223): code around pc:
I/DEBUG   (24223): ab14b0c4 e1500001 e92d4070 e1a05001 e1a04000
I/DEBUG   (24223): ab14b0d4 0a00001a e1a06005 ebffff9f e1a0c004
I/DEBUG   (24223): ab14b0e4 e8b6000f e8ac000f e8b6000f e8ac000f
I/DEBUG   (24223): ab14b0f4 e8960003 e88c0003 e5950004 e3500000
I/DEBUG   (24223): ab14b104 0a000001 e2800004 ebff7655 e5950000
I/DEBUG   (24223):
I/DEBUG   (24223): code around lr:
I/DEBUG   (24223):
I/DEBUG   (24223): stack:
I/DEBUG   (24223):     be8adeb8  afd4372c  /system/lib/libc.so
I/DEBUG   (24223):     be8adebc  0000003b
I/DEBUG   (24223):     be8adec0  005003c8  [heap]
I/DEBUG   (24223):     be8adec4  00000000
I/DEBUG   (24223):     be8adec8  be8ae130  [stack]
I/DEBUG   (24223):     be8adecc  4187369c
I/DEBUG   (24223):     be8aded0  41873688
I/DEBUG   (24223):     be8aded4  afd0c737  /system/lib/libc.so
I/DEBUG   (24223):     be8aded8  005003d0  [heap]
I/DEBUG   (24223):     be8adedc  00000000
I/DEBUG   (24223):     be8adee0  00000000
I/DEBUG   (24223):     be8adee4  ab14af6c  /system/lib/libskia.so
I/DEBUG   (24223):     be8adee8  005003d0  [heap]
I/DEBUG   (24223):     be8adeec  00000000
I/DEBUG   (24223):     be8adef0  df002777
I/DEBUG   (24223):     be8adef4  e3a070ad
I/DEBUG   (24223): #00 be8adef8  005003d0  [heap]
I/DEBUG   (24223):     be8adefc  be8adf5c  [stack]
I/DEBUG   (24223):     be8adf00  00000000
I/DEBUG   (24223):     be8adf04  ab14b1ac  /system/lib/libskia.so
I/DEBUG   (24223): #01 be8adf08  005003c8  [heap]
I/DEBUG   (24223):     be8adf0c  ab168970  /system/lib/libskia.so
I/DEBUG   (24223): debuggerd committing suicide to free the zombie!
I/DEBUG   (24516): debuggerd: Dec  8 2010 19:11:01
I/BootReceiver(  114): Copying /data/tombstones/tombstone_08 to DropBox (SYSTEM_TOMBSTONE)
I/ActivityManager(  114): Process --- name of my package --- (pid 24329) has died.
D/Zygote  (   63): Process 24329 terminated by signal (11)
E/ActivityManager(  114): fail to set top app changed!
D/Sensors (  114): close_akm, fd=122
I/UsageStats(  114): Unexpected resume of com.htc.launcher while already resumed in  --- name of my package ---
W/InputManagerService(  114): Got RemoteException sending setActive(false) notification to pid 24329 uid 10109

从它的外观来看,我的应用程序正在尝试访问内存地址00000000并且正在抛出一个段错误。

我在HTC Evo 4G上运行Android 2.2。我还没有能够在其他硬件上测试应用程序,但我想知道为什么它会崩溃。

修改

我在模拟器上运行了测试。现在,我得到了一个OutOfMemory异常来加载位图。我只是以编程方式加载两个位图。其他一切都是通过xml。

E/AndroidRuntime(  613): FATAL EXCEPTION: main
E/AndroidRuntime(  613): java.lang.RuntimeException: Unable to start activity ComponentInfo{---package name---/-- activity name ---}: android.view.InflateException: Binary XML file line #19: Error inflating class <unknown>
E/AndroidRuntime(  613):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(  613):        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(  613):        at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3815)
E/AndroidRuntime(  613):        at android.app.ActivityThread.access$2400(ActivityThread.java:125)
E/AndroidRuntime(  613):        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2037)
E/AndroidRuntime(  613):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  613):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  613):        at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  613):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  613):        at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  613):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  613):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(  613):        at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  613): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class <unknown>
E/AndroidRuntime(  613):        at android.view.LayoutInflater.createView(LayoutInflater.java:513)
E/AndroidRuntime(  613):        at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime(  613):        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
E/AndroidRuntime(  613):        at android.app.Activity.setContentView(Activity.java:1647)
E/AndroidRuntime(  613):        at --- activity name ---.onCreate(--- activity name ---.java:92)
E/AndroidRuntime(  613):        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(  613):        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(  613):        ... 12 more
E/AndroidRuntime(  613): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime(  613):        at android.widget.RelativeLayout.<init>(RelativeLayout.java:170)
E/AndroidRuntime(  613):        at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime(  613):        at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
E/AndroidRuntime(  613):        at android.view.LayoutInflater.createView(LayoutInflater.java:500)
E/AndroidRuntime(  613):        ... 23 more
E/AndroidRuntime(  613): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
E/AndroidRuntime(  613):        at android.graphics.Bitmap.nativeCreate(Native Method)
E/AndroidRuntime(  613):        at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
E/AndroidRuntime(  613):        at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
E/AndroidRuntime(  613):        at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
E/AndroidRuntime(  613):        at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
E/AndroidRuntime(  613):        at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462)
E/AndroidRuntime(  613):        at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:323)
E/AndroidRuntime(  613):        at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
E/AndroidRuntime(  613):        at android.content.res.Resources.loadDrawable(Resources.java:1709)
E/AndroidRuntime(  613):        at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime(  613):        at android.view.View.<init>(View.java:1885)
E/AndroidRuntime(  613):        at android.view.View.<init>(View.java:1834)
E/AndroidRuntime(  613):        at android.view.ViewGroup.<init>(ViewGroup.java:285)
E/AndroidRuntime(  613):        ... 27 more

我的活动的第92行是setContentView(R.layout.main),所以当它膨胀主要布局时它似乎崩溃了。加载我用于背景的位图时遇到问题。如何转储位图的内存或重用它们?我不是要控制程序中的那些,所以它在Android上都是自动化的。

1 个答案:

答案 0 :(得分:2)

似乎错误是由libskia.so产生的。请参阅similar error的此帖子。当内存不足时,似乎会产生错误。

如何加载资源,例如图片?在方向更改时,将重新创建活动,并且通常会再次加载所有资源。尝试缓存你的图像,但是beware of memory leaks(即缓存位图,而不是drawables)。

<强>更新

所以这似乎是由图像加载触发的。谷歌地图还会下载并实例化大量图像(地图图块),这可能会使情况变得更糟。

如果您的图片非常大,请尝试scale it when loading

还可以onRetainNonConfigurationInstance / getLastNonConfigurationInstance使用cache bitmaps for faster loading and less memory usage

<强>更新

此外,在屏幕上显示的适当大小的XML文件中使用图像,因为较大的图像会使问题膨胀。

相关问题