OutofMemory error in Android

前端 未结 2 571
一个人的身影
一个人的身影 2021-01-28 09:50

I have created one game which uses images and my game is in portrait and landscape mode. I have 2 different layout for that When i switch from 1 orientation to other, after doin

相关标签:
2条回答
  • 2021-01-28 10:06

    i got the solution from this link http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html

    i have a lots of images are setting in imageview every time orientation changes. i just make backgorund image static and problem solved

    private static Drawable BackgroundP;
    private static Drawable BackgroundL;
    
    if (conf.orientation == Configuration.ORIENTATION_LANDSCAPE){
       if(BackgroundL == null){
          BackgroundL = getResources().getDrawable(R.drawable.backgroundland);
       }
    } else {
       if(BackgroundP == null){
          BackgroundP = getResources().getDrawable(R.drawable.backgroundport);
       }
    }
    

    this will only set drawble one time.

    hope this will help anyone.

    0 讨论(0)
  • 2021-01-28 10:15

    @djk Oh yeah, it will load drawable one time, but will also create memory leak. This article explains why: http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html

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