2
votes

My app takes pictures with MediaStore.ACTION_IMAGE_CAPTURE Intent. The problem is that intermittently the app crashes after I press the shutter button but before the "OK" and "Cancel" buttons, that allow me to retake or accept the picture, are shown. The Ok and Cancel button selection is part of the intent and not my code so the crash seems to not be directly caused by my code.

The app just closes and no error message is shown, logcat doesn't react and the cpu/network/memory monitors just suddenly stops and says "The monitor is disabled".

private void dispatchTakePictureIntent() {

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, getPhotoFileUri(photoFileName));

    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    }
}

the photoFileName is always file:///storage/emulated/0/Android/data/com.companyname.appname/files/Pictures/AppName/myphoto.jpg

After the picture is taken it is handled by this code

private List<Bitmap> myImages;
enter code here
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode != RESULT_CANCELED) {

        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {

            if (resultCode == RESULT_OK) {
                Uri takenPhotoUri = getPhotoFileUri(photoFileName);
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inSampleSize = 4;
                Bitmap takenImage = BitmapFactory.decodeFile(takenPhotoUri.getPath(), options);

                //Store image in memory
                myImages.add(takenImage);

                if (myImagesAdapter == null) {
                    myImagesAdapter = new MyImagesListViewAdapter(this, myImages);

                    GridView myListView = (GridView) findViewById(R.id.my_images_view);
                    myListView.setAdapter(myImagesAdapter);
                    myImagesAdapter.notifyDataSetChanged();
                } else {
                    myImagesAdapter.notifyDataSetChanged();
                }

            } else { // Result was a failure
                Toast.makeText(this, "Picture wasn't taken!", Toast.LENGTH_SHORT).show();
            }
        }
    }
}

Additionally is seems this occurs more often/only when in debug mode (pressing the bug in android studio) and not when I run it (press the play button).

This has happened when taking the first picture but also on the second, third and fourth.

UPDATE 1 When I change logcat to ha No Filters I get these rows

09-06 22:30:26.961 990-1473/? I/WindowState: WIN DEATH: Window{296d6791 u0 com.mycompany.myapp/com.mycompany.myapp.MyFirstActivity}

09-06 22:30:26.965 990-1473/? D/InputDispatcher: Window went away: Window{296d6791 u0 com.mycompany.myapp/com.mycompany.myapp.MyFirstActivity}

09-06 22:30:26.968 990-2174/? I/WindowState: WIN DEATH: Window{3ac0ee0b u0 com.mycompany.myapp/com.mycompany.myapp.MySecondActivity}

09-06 22:30:26.971 990-2174/? D/InputDispatcher: Window went away: Window{3ac0ee0b u0 com.mycompany.myapp/com.mycompany.myapp.MySecondActivity}

09-06 22:30:27.059 990-1819/? I/ActivityManager: Process com.mycompany.myapp (pid 8623) has died

09-06 22:30:27.626 990-2174/? I/ActivityManager: Force stopping com.mycompany.myapp appid=10170 user=0: from pid 9949

09-06 22:30:27.627 990-2174/? I/ActivityManager: Force finishing activity ActivityRecord{18ca1aa0 u0 com.mycompany.myapp/.MyFirstActivity t254}

09-06 22:30:27.631 990-2174/? I/ActivityManager: Force finishing activity ActivityRecord{15946ece u0 com.mycompany.myapp/.MySecondActivity t254}

09-06 22:30:27.666 2249-2249/? W/NearbyMessages: ClientAppContext: 0P identifier(com.mycompany.myapp) without 0P prefix(0p:)

2
please add the logcat result for more details.W4R10CK
Unfortunately there is absolutely no logcat output.Mathias Rönnlund
If there is crash, there is logcat result. Try crashing app using external device.W4R10CK
As stated earlier "The app just closes and no error message is shown, logcat doesn't react and the cpu/network/memory monitors just suddenly stops and says 'The monitor is disabled'". So there is no crash as such, all of a sudden the app just disappears from the device screen.Mathias Rönnlund

2 Answers

0
votes

The problem seems to occur less frequently (not remedied) if I delete any pre-existing file with the same name so I changed the first method to

private void dispatchTakePictureIntent() {
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Uri filename = getPhotoFileUri(photoFileName);

    File imageFile = new File(filename.getPath());
    if (imageFile.exists()) {
        imageFile.delete();
    }

    intent.putExtra(MediaStore.EXTRA_OUTPUT, filename);

    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    }
}

and the second method to

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    ...
                Bitmap takenImage = BitmapFactory.decodeFile(takenPhotoUri.getPath(), options);

                File imageFile = new File(takenPhotoUri.getPath());
                if (imageFile.exists()) {
                    imageFile.delete();
                }

                myImages.add(takenImage);
    ...
0
votes

Somehow this only occurs in debug mode. When running the app with "Run 'app'" it never crashes. No idea why this is happening.

In logcat if I filter to the selected application (verbose) I get the first row and then several of the next row

10-07 13:54:48.538 16352-16352/com.fujitsu.helgaclient W/ContextImpl: Failed to ensure directory: /storage/external_SD/Android/data/com.fujitsu.helgaclient/files/Pictures
10-07 13:54:50.282 16352-16352/com.fujitsu.helgaclient D/BubblePopupHelper: isShowingBubblePopup : false

These I get about when I'm starting the camera intent and then nothing. So when I press the shutter and the app crashes logcat shows nothing for the current app. If I remove the filter there is so muched logged that it's impossible to find the rows being emitted at the same time as the crash.