我的应用程序正在我的物理设备(MotoG3)和仿真器(Nexus 5)上运行,并通过了Google Play开发者控制台上的启动前崩溃测试中的13台设备中的11台通过了测试。发生故障的两个设备位于Galaxy Note 2和3(Android 4.4)上,如下图所示-

java - 仅在Galaxy Note 2和3中出现OutofMemoryError-LMLPHP

我不确定出了什么问题,是否有内存泄漏,如果是的话该如何捕捉?这对我来说是全新的。

outOfMemoryError是-

FATAL EXCEPTION: main
 Process: com.tdp.tdp, PID: 17269
 java.lang.OutOfMemoryError
    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
    at android.content.res.Resources.loadDrawable(Resources.java:3054)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
    at android.widget.ImageView.<init>(ImageView.java:133)
    at android.support.v7.widget.au.<init>(Unknown Source)
    at android.support.v7.widget.au.<init>(Unknown Source)
    at android.support.v7.a.bh.a(Unknown Source)
    at android.support.v7.a.as.c(Unknown Source)
    at android.support.v7.a.as.a(Unknown Source)
    at android.support.v4.view.ak.onCreateView(Unknown Source)
    at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:173)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:690)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    at com.thedailypiece.thedailypiece.c.a(Unknown Source)
    at android.support.v4.app.n.b(Unknown Source)
    at android.support.v4.app.z.a(Unknown Source)
    at android.support.v4.app.z.a(Unknown Source)
    at android.support.v4.app.e.run(Unknown Source)
    at android.support.v4.app.z.e(Unknown Source)
    at android.support.v4.app.z.b(Unknown Source)
    at android.support.v4.app.ah.b(Unknown Source)
    at android.support.v4.view.ViewPager.a(Unknown Source)
    at android.support.v4.view.ViewPager.a(Unknown Source)
    at android.support.v4.view.ViewPager.a(Unknown Source)
    at android.support.v4.view.ViewPager.setCurrentItem(Unknown Source)
    at com.github.paolorotolo.appintro.AppIntroViewPager.setCurrentItem(Unknown Source)
    at com.github.paolorotolo.appintro.b.onClick(Unknown Source)
    at android.view.View.performClick(View.java:4630)
    at android.view.View$PerformClick.run(View.java:19339)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5335)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
    at dalvik.system.NativeStart.main(Native Method)

最佳答案

Galaxy Notes具有非标准的dpi配置。他们可能正在加载非常大的位图(或按比例放大您提供的位图)。 (Why does my Galaxy Note 3 have the same DP dimensions as a much smaller phone?

您有一些解决方案,

提供图像资产的所有dpi级别,因此系统不必缩放缺少的分辨率。

使用图像库(例如Glide或Picasso)以最佳分辨率加载图像。

最重要的是,确保将文件切成正确的大小。如果无法在屏幕上显示,则拥有超大位图将毫无用处。

关于java - 仅在Galaxy Note 2和3中出现OutofMemoryError,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37377945/

10-10 16:40