1

このブロックが実行されるたびに、ビットマップ割り当てで最終的にクラッシュするまで、DDMS で使用されるメモリ % が毎回 2% ずつ増加するという、いくつかのメモリの問題があります。

    Uri U = null;

    try {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            // We can read and write the media
            File path = this.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
            File file = new File(path, "image.jpg");
            path.mkdirs();

            FileOutputStream Os = new FileOutputStream(file);
            getFullResFilteredImage().compress(Bitmap.CompressFormat.JPEG, 80, Os);

            Os.flush();
            Os.close();
            Os = null;

            U = Uri.fromFile(file);
            file.deleteOnExit();
            file = null;
        } else {
            Toast toast = Toast.makeText(PrintLabActivity.this.getApplicationContext(), 
                    PrintLabActivity.this.getResources().getString(R.string.sd_image_error), Toast.LENGTH_SHORT);
            toast.show();
            return;
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    Intent i = new Intent(Intent.ACTION_SEND);
    i.setType("image/jpg");
    i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    i.putExtra(Intent.EXTRA_STREAM, U);

    i.putExtra(Intent.EXTRA_SUBJECT, this.getResources().getString(R.string.email_subject));
    String message = this.getResources().getString(R.string.email_message, PNBApplication.MARKETPLACE_URL, PNBApplication.MARKETPLACE_URL);
    i.putExtra(Intent.EXTRA_TEXT   , Html.fromHtml(message));
    U = null;

    this.startActivity(Intent.createChooser(i,"Send Image To:"));

このコードに漏れる可能性のあるものが何もない場合、毎回何が割り当てられているかを知る方法はありますか?

4

1 に答える 1

0

BitmapFactory.Options.inSampleSizeを使用して、ビットマップを作成するときのメモリ消費を減らすことができます。

より詳細な回答については、getFullResFilteredImage()メソッドを投稿してください。

于 2011-08-10T06:11:54.947 に答える