gpt4 book ai didi

Android 不在 OnActivityResult 中显示对话框

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:54 24 4
gpt4 key购买 nike

我正在调用相机 Intent 并在 onActivityResult() 中处理位图。我正在通过工作正常的 NDK 处理图像。然后我想打开一个对话框来显示图像,但没有任何反应。

   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);
}

现在我发现在其他机器上(不是在我的机器上)会抛出一个错误:

MainActivity has leaked window that was originally added here

我感觉来自 onCreate() 方法的代码有时会取消对话框?虽然只有 UI 的东西和一些后端通信开始了

更新:在另一个设备(更快,SGS6 而不是 SGS$)上运行应用程序时,致命信号 11 (SIGSEGV),代码 1,故障地址 0x24 in tid 12737 (RenderThread)。出现对话框,单击其中一个 ImageView 时出现此错误

最佳答案

尝试在 OnActivityResult 中设置一个您需要显示对话框的标志,并在 onResume 中检查该标志,然后在那里而不是在 中创建对话框OnActivityResult.

有关为什么在 Activity 生命周期方法中提交 fragment 事务(在本例中显示对话框)是一个坏主意的更多信息,请参见 here .

关于Android 不在 OnActivityResult 中显示对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36158355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com