从一个Activity切换到另一个Activity会导致Samsung设备出现OOM错误

时间:2015-02-26 23:32:07

标签: java android eclipse

我有一个Activity包含3个Fragments,另一个Activity包含3个Fragments。在每个Fragment中,我有10张PNG图片,每张图片的大小约为8kB。当我从第一个Activity切换到另一个时,我收到此错误:

02-27 00:19:28.973: E/AndroidRuntime(14652): FATAL EXCEPTION: main
02-27 00:19:28.973: E/AndroidRuntime(14652): android.view.InflateException: Binary XML file line #78: Error inflating class <unknown>
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.LayoutInflater.createView(LayoutInflater.java:619)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:666)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at com.uustaga.vista.Fragment6.onCreateView(Fragment6.java:42)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:482)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:1896)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2033)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2401)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2091)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2401)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2091)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2401)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2091)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2305)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1575)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.app.Activity.dispatchTouchEvent(Activity.java:2470)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2253)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.View.dispatchPointerEvent(View.java:7875)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3976)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3860)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5103)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5082)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5180)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.os.MessageQueue.nativePollOnce(Native Method)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.os.MessageQueue.next(MessageQueue.java:125)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.os.Looper.loop(Looper.java:138)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.app.ActivityThread.main(ActivityThread.java:5319)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at java.lang.reflect.Method.invokeNative(Native Method)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at java.lang.reflect.Method.invoke(Method.java:511)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at dalvik.system.NativeStart.main(Native Method)
02-27 00:19:28.973: E/AndroidRuntime(14652): Caused by: java.lang.reflect.InvocationTargetException
02-27 00:19:28.973: E/AndroidRuntime(14652):    at java.lang.reflect.Constructor.constructNative(Native Method)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.view.LayoutInflater.createView(LayoutInflater.java:593)
02-27 00:19:28.973: E/AndroidRuntime(14652):    ... 45 more
02-27 00:19:28.973: E/AndroidRuntime(14652): Caused by: java.lang.OutOfMemoryError
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
02-27 00:19:28.973: E/AndroidRuntime(14652):    at android.graphics.draw

我已经在Blackberry 7'平板电脑,Alcatel OT手机和三星手机上测试过这款应用程序,只有在三星Core2上才会出现这种情况。

1 个答案:

答案 0 :(得分:0)

我尝试了各种方法来实现更有创意的内容,例如:

    BitmapFactory.Options options = new BitmapFactory.Options ();
    options.inJustDecodeBounds = true;
    ...

为了更好地防止内存流出,但我没有成功。最后我决定使用

    android:largeHeap = "true" 

在我的应用程序清单文件的标记下,这解决了我的问题。 也许这种解决方案不可取,但有效。