Camera Intent destroys Activity

Alexander Parunov

I am posting this question after several days of fighting with this problem. I have Floating Action Button and onClick listener calls takePhoto() method, where I obviously want to take a photo and save its Bitmap, which I will use later to save it in Database. But that's not the main problem. I start onActivityResult (...) to get data of taken photo. When I take photo and click save, the activity is simply destroyed (I used Log.v (...) to check if it actually is destroyed) I tried almost everything including overriding onSaveInstanceState (...) and so on. Here is my Android manifest file and part of that code.

Manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alexparunov.collegemascots" >

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".account.SignIn"
              android:label="@string/title_activity_login">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".account.SignUp"
              android:label="@string/title_activity_register"/>
    <activity
        android:name=".profile.MainProfile"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:screenOrientation="portrait"
        android:noHistory="true"/>
</application>

Java: private static final int REQUEST_IMAGE_CAPTURE = 1;

private void takePhoto(){
    if(ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED){
        ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.CAMERA},1);
    }
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if(cameraIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(cameraIntent, REQUEST_IMAGE_CAPTURE);
    }
    Image finalImage = new Image();
    if(user != null && imageBitmap != null) {
        finalImage.setImageOwner(user.getUsername());
        finalImage.setImageName(generateName());
        finalImage.setImage(ImageUtils.getBytesFromBitmap(imageBitmap));

        try {
            ImageDatabase imageDatabase = new ImageDatabase(this);
            imageDatabase.open();
            finalImage.setImageId(imageDatabase.createImage(finalImage));
            Log.v("TakeImage",""+finalImage.getImageId());
            imageDatabase.close();
            images.add(finalImage);
            user.setImages(images);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {
        Bundle extras = data.getExtras();
        imageBitmap = (Bitmap) extras.get("data");
    }
}

private String generateName(){
    String name = user.getName()+"_";
    if(images != null) {
        name += images.size() + ".png";
    }
    return name;
}
Lovenkrands

I think it's the android:noHistory="true"... Looks like after taking the photo it returns to the previous activity on the history stack but there is no activity in there as it is set to keep no history.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Camera Intent not returning to calling Activity

From Dev

Camera Intent vs Activity/Fragment

From Dev

Camera Intent not returning to calling Activity

From Dev

android camera intent use another activity

From Dev

camera captured image intent to other activity?

From Dev

Intent.FLAG_ACTIVITY_CLEAR_TOP destroys the destination activity. How to avoid?

From Dev

Open camera directly in the Activity without clicking on button and without intent?

From Dev

on activity result camera intent return null in samsung s4

From Dev

Android Tablet Take Picture Camera Intent Activity Restarts

From Dev

Activity rotates after taking camera through intent in S4

From Dev

why while calling camera in android all varibles(got from Activity1 through intent ) in the activity are reinitilized?

From Dev

Unable to resume activity on onActivityResult when ACTION_IMAGE_CAPTURE intent returns on landscape camera orientation

From Dev

is it possible to programmatically call the capture button on a camera intent from its calling activity

From Dev

How to properly error-catch Android camera activity when using the ACTION_IMAGE_CAPTURE Intent

From Dev

Orientation changes destroys ftp uploading in android activity?

From Dev

Camera Intent in Fragment

From Dev

Unable to StartActivityForResult() with camera Intent

From Dev

Camera Intent call onDestroy()

From Dev

Unable to StartActivityForResult() with camera Intent

From Dev

fileNotFoundException camera intent - Android

From Dev

Android: Why clicking on notification of intent with backstack destroys parent MainActivity?

From Dev

Get the Intent that resumes the activity

From Dev

In login activity, intent is not working

From Dev

How to receive Intent in Activity

From Dev

Passthrough intent filter and activity

From Dev

back to previous activity with intent

From Dev

Intent not working - Activity not found

From Dev

Android Intent, Fragment and Activity

From Dev

Intent JSONObject to another activity

Related Related

  1. 1

    Camera Intent not returning to calling Activity

  2. 2

    Camera Intent vs Activity/Fragment

  3. 3

    Camera Intent not returning to calling Activity

  4. 4

    android camera intent use another activity

  5. 5

    camera captured image intent to other activity?

  6. 6

    Intent.FLAG_ACTIVITY_CLEAR_TOP destroys the destination activity. How to avoid?

  7. 7

    Open camera directly in the Activity without clicking on button and without intent?

  8. 8

    on activity result camera intent return null in samsung s4

  9. 9

    Android Tablet Take Picture Camera Intent Activity Restarts

  10. 10

    Activity rotates after taking camera through intent in S4

  11. 11

    why while calling camera in android all varibles(got from Activity1 through intent ) in the activity are reinitilized?

  12. 12

    Unable to resume activity on onActivityResult when ACTION_IMAGE_CAPTURE intent returns on landscape camera orientation

  13. 13

    is it possible to programmatically call the capture button on a camera intent from its calling activity

  14. 14

    How to properly error-catch Android camera activity when using the ACTION_IMAGE_CAPTURE Intent

  15. 15

    Orientation changes destroys ftp uploading in android activity?

  16. 16

    Camera Intent in Fragment

  17. 17

    Unable to StartActivityForResult() with camera Intent

  18. 18

    Camera Intent call onDestroy()

  19. 19

    Unable to StartActivityForResult() with camera Intent

  20. 20

    fileNotFoundException camera intent - Android

  21. 21

    Android: Why clicking on notification of intent with backstack destroys parent MainActivity?

  22. 22

    Get the Intent that resumes the activity

  23. 23

    In login activity, intent is not working

  24. 24

    How to receive Intent in Activity

  25. 25

    Passthrough intent filter and activity

  26. 26

    back to previous activity with intent

  27. 27

    Intent not working - Activity not found

  28. 28

    Android Intent, Fragment and Activity

  29. 29

    Intent JSONObject to another activity

HotTag

Archive