Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6373615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:23:03+00:00 2026-05-25T01:23:03+00:00

I have an activity A where I’m building my own camera.In this activity the

  • 0

I have an activity A where I’m building my own camera.In this activity the camera is opened and when the use presses a button a picture is taken.

This is done like this:

Activity A:
  //this button needs to be pressed to take the photo

  public void onClick(View arg0) {
  mCamera.takePicture(null, mPictureCallback, mPictureCallback);
            }

  //the method that gets called
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
    public void onPictureTaken(byte[] imageData, Camera c) {

        if (imageData != null) {
            Intent mIntent = new Intent();


            Bundle b = new Bundle();
            b.putByteArray("imageData", imageData);
            Intent i = new Intent(mContext, ViewPhoto.class);
            i.putExtras(b);
            startActivity(i);

            setResult(FOTO_MODE, mIntent);
            finish();

        }
    }
};

The picture is sent to a second activity where the user can view it and see if it likes it or not.If he doesn’t likes it he can then retake the photo

Activity B:

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
                //..........
       Bundle extras = getIntent().getExtras();
       BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 2;
    byte[] imageData = extras.getByteArray("imageData");
    Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
            imageData.length, options);

    Matrix mat = new Matrix();
    mat.postRotate(90);
    bitmapResult = Bitmap.createBitmap(myImage, 0, 0, myImage.getWidth(),
            myImage.getHeight(), mat, true);

               //.......
                 } 

In this second activity I receive the bytes of the picture and create a first bitmap:

 Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
                imageData.length, options);

After that I need to rotate the first bitmap creating a second bitmap:

bitmapResult = Bitmap.createBitmap(myImage, 0, 0, myImage.getWidth(),
                myImage.getHeight(), mat, true);

After the user sees bitmapResult he can retake the photo.

backTakePhoto.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            //...back to activity A
        }
    });

The problem is that after taking several photos, loops like:

 activity A->activity B->activity A->Activity B my app crashes in activity B at this line:

bitmapResult = Bitmap.createBitmap(myImage, 0, 0, myImage.getWidth(),
                myImage.getHeight(), mat, true);

And this is how my logcat looks like:

 FATAL EXCEPTION: main
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
at com.Xperiaproject.ViewPhoto.onCreate(ViewPhoto.java:71)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:862)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity com.Xperiaproject/.ViewPhoto

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:23:03+00:00Added an answer on May 25, 2026 at 1:23 am

    You don’t have enough memory to creat your bitmap. That’s why it crashes.

    To free your memory you should recycle your bitmap when unused or save it to the sd card then recycle.

    bitmapResult.recycle();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have activity A where authentication is done. After this user redirected to other
At this moment I have activity (lview) with list view which use images downloaded
I have an activity with the following layout. So in this screen, initally the
I have an activity that extends ExpandableListActivity. I use SimpleCursorTreeAdapter to fill ExpandableListView. My
I have an Activity in which when I press back button then its not
I have an activity that launches another one using startActivityForResult. This step is ok.
I have activity with MapView, TextView, 3 ImageButton and 1 simple Button. First call
Please help me this question. Example I have Activity class MyActivity. I start this
I have activity records that have an inline formset showing appointments. I use the
I have Activity with ListView and buttons - clear all and OK. On button

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.