2016-03-22 10 views
1

私はカメラのインテントを呼び出して、onActivityResult()でビットマップを処理しています。私は正常に動作しているNDK経由で画像を処理しています。それから私は画像を提示するダイアログを開きたいが、何も起こらない。AndroidはOnActivityResultのダイアログを表示しません

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()メソッドのコードは時々ダイアログをキャンセルしていることを感じています?別のdeivce(高速、SGS6上でアプリケーションを実行する代わりの場合致命的なシグナル11(SIGSEGV)、コード1、故障ADDRの0x24をTID 12737(RenderThread)においてのみUIものといくつかのバックエンド通信は

UPDATEを開始しているがSGS $)。ダイアログボックスが表示され、画像ビューのいずれかをクリックするとこのエラーが発生します

+0

ここで*正確に*あなたはこのコードを呼び出しますか?私はあなたがメインスレッドで画像を処理していないと仮定します。 –

+0

私はそれをonActivityresult()で呼び出し、自分自身で新しいスレッドを開始しません。 NDKの処理方法がわからないとにかく、NDKの部分はまだ正常に動作しています(私はすべてのログを取得し、ファイルが作成されます)。しかし、ダイアログは表示されません。 ImageViewsをダイアログに追加して、処理された画像を表示します。 callOnClick()を呼び出すと、致命的なエラーが発生します(いくつかのメモリはアクセスであり、許可されていないようです) – 4ndro1d

+0

'dialog.show()'に実際に到達したことを確認できますか? –

答えて

2

OnActivityResultにフラグを設定してダイアログを表示し、そのフラグをonResumeにチェックしてから、の代わりにダイアログを作成してみてください。

アクティビティライフサイクルメソッドでフラグメントトランザクション(この場合はダイアログを表示)をコミットすることが悪い考えは、hereです。

0

MainActivityでダイアログを表示すると、MainActivityがフォアグラウンドになっていることを示すフラグをチェックできます。

それはこのように可能になります

boolean isActivityResumed = true; 

@Override 
protected void onResume() { 
    // TODO Auto-generated method stub 
    // When activity is in focus, it will be on resumed. 
    super.onResume(); 
    isActivityResumed = true; 
} 

@Override 
protected void onPause() { 
    // TODO Auto-generated method stub 
    // When activity is out of focus, it will be on paused. 
    super.onPause(); 
    isActivityResumed = false; 
} 

その後、あなたはあなたのダイアログを表示する場合、このフラグをチェックしてください。

if (isActivityResumed && dialog != null) { 
    dialog.show(); 
} 
0

は、このようなあなたのダイアログを作成してください:

final Dialog dialog = new Dialog(context); 
    dialog.setTitle("Only select properly segmented pictures:"); 
    dialog.setContentView(R.layout.dialog_segmen); 
    Button dialogButtonRetry= (Button) dialog.findViewById(R.id.dialogButtonRetry); 
    dialogButtonRetry.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      dispatchTakePictureIntent(); 
     } 
    }); 
    Button dialogButtonDone= (Button) dialog.findViewById(R.id.dialogButtonDone); 
    dialogButtonDone.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      dialog.dismiss(); 
     } 
    }); 

    dialog.show(); 

ivWahetLeftを取得するには

ImageView ivWahetLeft = (ImageView) dialog.findViewById(R.id.ivWahetLeft); 
関連する問題