R
r4in
Ambitioniertes Mitglied
- 3
Hi zusammen,
folgendes Problem, in meiner App speichere ich Fotos ab. Bei meinem Galaxy S2 überhaupt kein Problem, da kann ich soviele Foto aufnehmen und abspeichern wie ich möchte. Benutze ich die App auf meinem Galaxy S3 fliegt mir nach 2 - 4 Fotos die App um die Ohren mit OutOfMemoryException.
Auslösen des Intens:
In Activity Result:
nun ist meine Frage, was hab ich falsch gemacht bzw übersehen.
Der GC räumt zwar den Speicher teilweise wieder frei, aber anscheinend nicht genug.
folgendes Problem, in meiner App speichere ich Fotos ab. Bei meinem Galaxy S2 überhaupt kein Problem, da kann ich soviele Foto aufnehmen und abspeichern wie ich möchte. Benutze ich die App auf meinem Galaxy S3 fliegt mir nach 2 - 4 Fotos die App um die Ohren mit OutOfMemoryException.
Auslösen des Intens:
Code:
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,
"Image");
Intent intent = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, REQUEST_CODE_FOTO);
Code:
if (requestCode == REQUEST_CODE_FOTO) {
if (resultCode == RESULT_OK) {
String fn = "";
Bitmap myBitmap = null;
FileOutputStream fileOutputStream = null;
int quality = 50;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inPurgeable=true;
try {
fn = convertImageUriToFileName(ObjectPool.getImageUri(), this);
myBitmap = BitmapFactory.decodeFile(fn);
File f = new File(fn);
f.delete();
fileOutputStream = new FileOutputStream(fn);
BufferedOutputStream bos = new BufferedOutputStream(
fileOutputStream);
myBitmap.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
myBitmap.recycle();
myBitmap = null;
bos = null;
System.gc();
} catch (Exception e) {
ObjectPool.appendLog("Maske -> " + e.toString());
e.getMessage();
// Toast.makeText(Maske.this, logStr, Toast.LENGTH_LONG);
return;
}
}
}
Code:
public static String convertImageUriToFileName(Uri imageUri,
Activity activity) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA,
MediaStore.Images.Media._ID,
MediaStore.Images.ImageColumns.ORIENTATION };
cursor = activity.managedQuery(imageUri, proj, // Which columns to
// return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int file_ColumnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
int orientation_ColumnIndex = cursor
.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION);
if (cursor.moveToFirst()) {
cursor.getString(orientation_ColumnIndex);
return cursor.getString(file_ColumnIndex);
}
return null;
} finally {
if (cursor != null) {
cursor.close();
}
}
}
nun ist meine Frage, was hab ich falsch gemacht bzw übersehen.
Der GC räumt zwar den Speicher teilweise wieder frei, aber anscheinend nicht genug.
Zuletzt bearbeitet: