FragmentActivity分配了太多内存

时间:2016-01-27 18:56:51

标签: android memory-management parse-platform bitmap

我的主要活动是一个画廊,它可以加载缓存100mb的照片,因为它们超过30个位图,所以还可以。 单击其中一个图像时遇到问题:我在Intent中传递一个id,并从Parse获取位图,以便在点击时加载Photo。

public class ImageFragment extends FragmentActivity {

ImageView imageView;
Bitmap imageBitmap;
public void onCreate(Bundle savedInstanceState) {
    final Context mContext = this;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_image);
    final View v = new View(this.getApplicationContext());

    String objectID = getIntent().getExtras().getString("objectID");
    final ImageView imageView= (ImageView) findViewById(R.id.image_view_fragment);

    ParseQuery<ParseObject> queryFoto = new ParseQuery<ParseObject>("Photo");
    queryFoto.whereEqualTo("objectId", objectID);
    queryFoto.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> objects, ParseException e) {
            if (e == null) {
                ParseFile f = objects.get(0).getParseFile("photo");
                f.getDataInBackground(new GetDataCallback() {
                    @Override
                    public void done(byte[] data, ParseException e) {

                        imageBitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                        //BitmapUtil.scala is a function 
                       imageView.setImageBitmap(BitmapUtil.scala(imageBitmap));
                      }
                    });
                } else {
//this is a fuction to check error
                    check(e.getCode(), v, e.getMessage());
                }
            }
        });
    }

这是scala函数

public static Bitmap scala(Bitmap imageBitmap){
        int w=imageBitmap.getWidth();
        int h=imageBitmap.getHeight();
        int maxsize=GL10.GL_MAX_TEXTURE_SIZE;
        System.out.println("w="+w+" h="+h+" maxsize="+maxsize);
        Bitmap scaledBitmap=imageBitmap;

    if (imageBitmap.getWidth() > GL10.GL_MAX_TEXTURE_SIZE ) {

        System.out.println("1");
        float aspect_ratio = ((float) imageBitmap.getWidth()) / ((float) imageBitmap.getHeight());

        int wout=maxsize-1;
        int hout= (int) (wout/aspect_ratio);
        System.out.println("aspect_ratio"+aspect_ratio+" wout"+wout+" hout"+hout);
        scaledBitmap = Bitmap.createScaledBitmap(imageBitmap,(int)wout-1, (int)hout-1,false);

    }

    if(imageBitmap.getHeight()>GL10.GL_MAX_TEXTURE_SIZE){
        System.out.println("2");
        float aspect_ratio = ((float) imageBitmap.getWidth()) / ((float) imageBitmap.getHeight());

        int hout=maxsize-1;
        int wout= (int) (aspect_ratio*hout);
        System.out.println("aspect_ratio"+aspect_ratio+" wout"+wout+" hout"+hout);
        scaledBitmap = Bitmap.createScaledBitmap(imageBitmap,(int)wout-1, (int)hout-1,false);
        return scaledBitmap;
    }

    return scaledBitmap;

}

所以问题是它只为这个活动分配了60mb,并且在按下后面时它不会解除分配。这张照片大概是1Mb,我试图对它进行扩展,但它还没有工作。

0 个答案:

没有答案