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 7875371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:58:18+00:00 2026-06-03T02:58:18+00:00

I am trying to take a picture using an intent. My problem is that

  • 0

I am trying to take a picture using an intent. My problem is that sometimes after taking a picture my activity, which calls startActivityForResult, seems to be destroyed so that onCreate is called again.

Here is my code for taking pictures after clicking an imageview, which image should be replaced:

if (!getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_CAMERA)) {
            Util.makeLongToast(R.string.lang_no_camera);
        } else {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, TAKE_ITEM_PHOTO);
        }

…

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.v(TAG, "onactivityresult called");
    if (requestCode == TAKE_ITEM_PHOTO) {
        if (data != null) {

            imageUri = data.getData();


                try {
                    img_photo.setImageBitmap(Media.getBitmap(
                            getContentResolver(), imageUri));
            } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

        } else
            Log.w(TAG, "data is null");
    }
}

So all i try is to take a picture and replace the image of an imageview with it. But in some cases onCreate is called after onActivityResult was called and the new image is lost.

Help is greatly appreciated.

  • 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-06-03T02:58:19+00:00Added an answer on June 3, 2026 at 2:58 am

    Actually the camera causes the orientation change in your activity that is why your activity is being destroyed and recreated.

    Add this in your manifest file it will prevent the orientation change and your activity will not get destroyed and recreated.

    <activity
        android:name=".YourActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:screenOrientation="portrait" >
    </activity>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a standard Intent that will take a picture, then allow
I'm trying to take a picture from the Camera using intent with onActivityResult but
I trying to put together an Android app that will take a picture and
I'm trying take the names that I am given by the program after it
I am writing an app that uses the camera intent to take a picture.
I'm taking a picture using my own camera and trying to save the result
I'm taking a picture using my own camera and trying to save the result
I am trying to write an Android application that will take a picture, put
I'm trying to use the CAMERA intent on adroid to take a picture and
I am trying to take an array that contains 400 integers, and split it

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.