I am using camera Intent to take a photo and populate it to ImageView
. I got an error whenever I take another photo from the camera Intent. It works well when I am only taking one photo but on second attempt without killing the application, the OutOfMemory Error pops up.
This is the logcat
01-02 09:51:39.930: E/AndroidRuntime(31339): FATAL EXCEPTION: main
01-02 09:51:39.930: E/AndroidRuntime(31339): java.lang.OutOfMemoryError
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:722)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:788)
01-02 09:51:39.930: E/AndroidRuntime(31339): at com.example.photosharingtest2.MainActivity.onActivityResult(MainActivity.java:218)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.app.Activity.dispatchActivityResult(Activity.java:5390)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.app.ActivityThread.deliverResults(ActivityThread.java:3178)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3225)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.app.ActivityThread.access$1100(ActivityThread.java:140)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.os.Handler.dispatchMessage(Handler.java:99)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.os.Looper.loop(Looper.java:137)
01-02 09:51:39.930: E/AndroidRuntime(31339): at android.app.ActivityThread.main(ActivityThread.java:4898)
01-02 09:51:39.930: E/AndroidRuntime(31339): at java.lang.reflect.Method.invokeNative(Native Method)
01-02 09:51:39.930: E/AndroidRuntime(31339): at java.lang.reflect.Method.invoke(Method.java:511)
01-02 09:51:39.930: E/AndroidRuntime(31339): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
01-02 09:51:39.930: E/AndroidRuntime(31339): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
01-02 09:51:39.930: E/AndroidRuntime(31339): at dalvik.system.NativeStart.main(Native Method)
This is what I did to get the camera to populate photo taken.
btn_takeImage = (Button) findViewById(R.id.btn_takeImage);
btn_takeImage.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// Intent camera_intent = new
// Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
// startActivityForResult(camera_intent, CAMERA_PIC_REQUEST);
values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "New Picture");
values.put(MediaStore.Images.Media.DESCRIPTION, "From your Camera");
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, PICTURE_RESULT);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
switch (requestCode)
{
case PICTURE_RESULT:
if (requestCode == PICTURE_RESULT)
if (resultCode == Activity.RESULT_OK)
{
try
{
thumbnail = MediaStore.Images.Media.getBitmap(getContentResolver(), imageUri);
img_backgroundImage.setImageBitmap(thumbnail);
imageurl = getRealPathFromURI(imageUri);
}
catch (Exception e)
{
e.printStackTrace();
}
}
break;
}
}