Android在OnActivityResult中不显示对话框

Android在OnActivityResult中不显示对话框,第1张

概述我正在调用相机意图并在onActivityResult()中处理位图.我正在通过NDK处理图像,效果很好.然后,我想打开一个对话框显示图像,但是什么也没有发生.privatevoidstartIrisRoutine(BitmapimageBitmap){FiletempDir=newFile(getFilesDir()+File.separator+Constan

我正在调用相机意图并在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).se@R_301_5411@Bitmap(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).se@R_301_5411@Bitmap(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).se@R_301_5411@Bitmap(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).se@R_301_5411@Bitmap(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内容和一些后端通信

更新:在另一个设备上运行该应用程序时,致命信号11(SIGSEGV),代码1,在tID 12737(RenderThread)中的故障地址0x24(更快,用SGS6代替SGS $).对话框出现,单击imagevIEws之一时出现此错误

解决方法:

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

有关在活动生命周期方法中提交片段事务(在这种情况下,显示对话框)为什么不是个好主意的更多信息,请参见here.

总结

以上是内存溢出为你收集整理的Android在OnActivityResult中不显示对话框全部内容,希望文章能够帮你解决Android在OnActivityResult中不显示对话框所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1090429.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存