jjzjj

Android 不在 OnActivityResult 中显示对话框

coder 2023-12-28 原文

我正在调用相机 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/

有关Android 不在 OnActivityResult 中显示对话框的更多相关文章

  1. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  2. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  3. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

  4. ruby-on-rails - 使用 Sublime Text 3 突出显示 HTML 背景语法中的 ERB? - 2

    所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择

  5. ruby-on-rails - link_to 不显示任何 rails - 2

    我试图在索引页中创建一个超链接,但它没有显示,也没有给出任何错误。这是我的index.html.erb代码。ListingarticlesTitleTextssss我检查了我的路线,我认为它们也没有问题。PrefixVerbURIPatternController#Actionwelcome_indexGET/welcome/index(.:format)welcome#indexarticlesGET/articles(.:format)articles#indexPOST/articles(.:format)articles#createnew_articleGET/article

  6. ruby-on-rails - 如何在 Rails View 上显示错误消息? - 2

    我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c

  7. ruby - 当使用::指定模块时,为什么 Ruby 不在更高范围内查找类? - 2

    我刚刚被困在这个问题上一段时间了。以这个基地为例:moduleTopclassTestendmoduleFooendend稍后,我可以通过这样做在Foo中定义扩展Test的类:moduleTopmoduleFooclassSomeTest但是,如果我尝试通过使用::指定模块来最小化缩进:moduleTop::FooclassFailure这失败了:NameError:uninitializedconstantTop::Foo::Test这是一个错误,还是仅仅是Ruby解析变量名的方式的逻辑结果? 最佳答案 Isthisabug,or

  8. ruby-on-rails - 复数 for fields_for has_many 关联未显示在 View 中 - 2

    目前,Itembelongs_toCompany和has_manyItemVariants。我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示该表单。只有当我使用单数时才会显示。我检查了我的关联,它们似乎是正确的,这可能与嵌套在公司下的项目有关,还是我遗漏了其他东西?提前致谢。注意:下面的代码片段中省略了不相关的代码。编辑:不知道这是否相关,但我正在使用CanCan进行身份验证。routes.rbresources:companiesdoresources:itemsenditem.rbclassItemi

  9. ruby-on-rails - 在 Flash 警报 Rails 3 中显示错误消息 - 2

    如果我在模型中设置验证消息validates:name,:presence=>{:message=>'Thenamecantbeblank.'}我如何让该消息显示在闪光警报中,这是我迄今为止尝试过的方法defcreate@message=Message.new(params[:message])if@message.valid?ContactMailer.send_mail(@message).deliverredirect_to(root_path,:notice=>"Thanksforyourmessage,Iwillbeintouchsoon")elseflash[:error]

  10. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

随机推荐