Android OutOfMemoryError in SetContentView line

后端 未结 4 1713
心在旅途
心在旅途 2020-12-21 05:51

When i try to open my chat class , sometimes it runs properly , sometimes it gives OutOfMemoryError at setContentView line.I can\'t understand what is the cause of problem?

相关标签:
4条回答
  • 2020-12-21 06:29

    I would check the size of all your images referred to in your ImageViews. If they are large, maybe encode them as different image types to reduce the image size. The Android system is periodically running out of memory and crashing your application currently. It makes sense that you are getting this only sometimes as it depends on how much memory is currently being used for other applications etc... . If you reduce the size of your images significantly you should be able to resolve this.

    0 讨论(0)
  • 2020-12-21 06:34

    Your OOM error is related to the Images you are loading as I am seeing in your log trace.

    See this for loading large Bitmaps more efficiently:

    A 400 KB image file can easily take up 5-10 MB of RAM.

    For requesting to incraese heap size dynamically, Use android:largeHeap="true" in the manifest.xml.

    or/and just use the proper function to decode...

    0 讨论(0)
  • 2020-12-21 06:39

    A few things to look at.

    Have you provided the background image(s) for several densities? Scaling is sometimes consuming a lot of memory.

    Do you use startActivity or startActivityForResult()? In the latter case, your older Activity objects cannot be destroyed.

    Do you collect information in the Application class?

    0 讨论(0)
  • 2020-12-21 06:44

    Increase the gradle.properties in the root of your project :

    org.gradle.jvmargs=-XX:MaxHeapSize\=512m -Xmx512m

    the default jvmargs is 256

    you can request to use more by using.

    android:largeHeap="true"
    

    in the manifest.xml.

    0 讨论(0)
提交回复
热议问题