I am calling the camera intent and handle the bitmap in the onActivityResult(). I am processing the image via NDK which is working fine. Then I want to open a dialog to present the image, but nothing happens.
private void startIrisRoutine(Bitmap imageBitmap) {
File tempDir = new File(getFilesDir() + File.separator + Constants.DIR_TEMP);
tempDir.mkdirs();
// create file for taken photo
final File inputFile = new File(tempDir + File.separator + Constants.FILE_INPUT + Constants.END_JPG);
// create face part files in temp folder
final File facePartFace = new File(tempDir + File.separator + Constants.FILE_FACE + Constants.END_PNG);
final File facePartEyeRight = new File(tempDir + File.separator + Constants.FILE_EYE_RIGHT + Constants.END_PNG);
final File facePartEyeLeft = new File(tempDir + File.separator + Constants.FILE_EYE_LEFT + Constants.END_PNG);
//create texture files
final File textureWahetRightFile = new File(tempDir + File.separator + Constants.FILE_TEXTURE + USITHelper.ALGO_SEG_WAHET_SHORT + Constants.FILE_EYE_RIGHT + Constants.END_PNG);
final File textureCahtRightFile = new File(tempDir + File.separator + Constants.FILE_TEXTURE + USITHelper.ALGO_SEG_CAHT_SHORT + Constants.FILE_EYE_RIGHT + Constants.END_PNG);
final File textureWahetLeftFile = new File(tempDir + File.separator + Constants.FILE_TEXTURE + USITHelper.ALGO_SEG_WAHET_SHORT + Constants.FILE_EYE_LEFT + Constants.END_PNG);
final File textureCahtLeftFile = new File(tempDir + File.separator + Constants.FILE_TEXTURE + USITHelper.ALGO_SEG_CAHT_SHORT + Constants.FILE_EYE_LEFT + Constants.END_PNG);
// create temp segmentation files
final File segmentationWahetRightFile = new File(tempDir + File.separator + Constants.FILE_SEGMENTS + USITHelper.ALGO_SEG_WAHET_SHORT + Constants.FILE_EYE_RIGHT + Constants.END_JPG);
final File segmentationCahtRightFile = new File(tempDir + File.separator + Constants.FILE_SEGMENTS + USITHelper.ALGO_SEG_CAHT_SHORT + Constants.FILE_EYE_RIGHT + Constants.END_JPG);
final File segmentationWahetLeftFile = new File(tempDir + File.separator + Constants.FILE_SEGMENTS + USITHelper.ALGO_SEG_WAHET_SHORT + Constants.FILE_EYE_LEFT + Constants.END_JPG);
final File segmentationCahtLeftFile = new File(tempDir + File.separator + Constants.FILE_SEGMENTS + USITHelper.ALGO_SEG_CAHT_SHORT + Constants.FILE_EYE_LEFT + Constants.END_JPG);
try {
FileOutputStream fos = new FileOutputStream(inputFile);
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mUSITHelper.findFaceParts(inputFile, facePartFace, facePartEyeLeft, facePartEyeRight);
mUSITHelper.segmentPicture(facePartEyeLeft, textureWahetLeftFile, segmentationWahetLeftFile, USITHelper.ALGO_SEG_WAHET);
mUSITHelper.segmentPicture(facePartEyeLeft, textureCahtLeftFile, segmentationCahtLeftFile, USITHelper.ALGO_SEG_CAHT);
mUSITHelper.segmentPicture(facePartEyeRight, textureWahetRightFile, segmentationWahetRightFile, USITHelper.ALGO_SEG_WAHET);
mUSITHelper.segmentPicture(facePartEyeRight, textureCahtRightFile, segmentationCahtRightFile, USITHelper.ALGO_SEG_CAHT);
final AlertDialog.Builder alertadd = new AlertDialog.Builder(this);
alertadd.setCancelable(false);
LayoutInflater factory = LayoutInflater.from(this);
View view = factory.inflate(R.layout.dialog_segmen, null);
alertadd.setTitle("Only select properly segmented pictures:");
alertadd.setView(view);
alertadd.setNegativeButton("Retry", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
dispatchTakePictureIntent();
}
});
alertadd.setPositiveButton("Done", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
dlg.dismiss();
}
});
final Dialog dialog = alertadd.create();
dialog.show();
ImageView ivWahetLeft = (ImageView) dialog.findViewById(R.id.ivWahetLeft);
ivWahetLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createIrisTemplate(textureWahetLeftFile, segmentationWahetLeftFile, USITHelper.ALGO_SEG_WAHET_SHORT, Constants.EYE_POSITION_LEFT);
v.setClickable(false);
v.setEnabled(false);
((ImageView) v).setImageBitmap(null);
}
});
final ImageView ivCahtLeft = (ImageView) dialog.findViewById(R.id.ivCahtLeft);
ivCahtLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createIrisTemplate(textureCahtLeftFile, segmentationCahtLeftFile, USITHelper.ALGO_SEG_CAHT_SHORT, Constants.EYE_POSITION_LEFT);
v.setClickable(false);
v.setEnabled(false);
((ImageView) v).setImageBitmap(null);
}
});
ImageView ivWahetRight = (ImageView) dialog.findViewById(R.id.ivWahetRight);
ivWahetRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createIrisTemplate(textureWahetRightFile, segmentationWahetRightFile, USITHelper.ALGO_SEG_WAHET_SHORT, Constants.EYE_POSITION_RIGHT);
v.setClickable(false);
v.setEnabled(false);
((ImageView) v).setImageBitmap(null);
}
});
ImageView ivCahtRight = (ImageView) dialog.findViewById(R.id.ivCahtRight);
ivCahtRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createIrisTemplate(textureCahtRightFile, segmentationCahtRightFile, USITHelper.ALGO_SEG_CAHT_SHORT, Constants.EYE_POSITION_RIGHT);
v.setClickable(false);
v.setEnabled(false);
((ImageView) v).setImageBitmap(null);
}
});
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage("file:///" + segmentationWahetLeftFile, ivWahetLeft);
imageLoader.displayImage("file:///" + segmentationCahtLeftFile, ivCahtLeft);
imageLoader.displayImage("file:///" + segmentationCahtRightFile, ivCahtRight);
imageLoader.displayImage("file:///" + segmentationWahetRightFile, ivWahetRight);
}
Now i figured out that on other machines (not on mine) there is an error thrown:
MainActivity has leaked window that was originally added here
I have the feeling that code from the onCreate() method is sometimes canceling the dialog? Although only UI stuff and some backend communication is started
UPDATE: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x24 in tid 12737 (RenderThread) when running the app on another deivce (faster, SGS6 instead of SGS$). Dialog shows up and I get this error when clicking one of the imageviews
Try setting a flag in OnActivityResult that you need to display the dialog, and check for that flag in onResume, then create your dialog there instead of in OnActivityResult.
More information on why it is a bad idea to commit a fragment transaction (in this case show a dialog) in activity lifecycle method can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With