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:)