2016-03-22 14 views
1

iletişim kutusunda görünmüyor. Fotoğraf makinesinin amacını arıyorum ve bitmap'i onActivityResult() 'da işliyorum. Görüntü düzgün çalışan NDK ile işliyorum. Sonra görüntüyü sunmak için bir diyalog açmak istiyorum ama hiçbir şey olmuyor.Android, OnActivityResult

MainActivity has leaked window that was originally added here 

I (onCreate gelen bu kodu his var) yöntemi bazen iletişim iptal ediyor:

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

Şimdi ben diğer makinelerden (değil mayına) atılan bir hata olduğunu anladım ? UI şeyler ve bazı arka uç haberleşme rağmen sadece

başlatıldığında

GÜNCELLEME: Ölümcül sinyali 11 (SIGSEGV), kod 1, tid 12737 (RenderThread) arıza addr 0x24 (daha hızlı, SGS6 yerine başka deivce Uygulamayı çalıştırırken SGS $). İletişim kutusu açılır ve görüntü hatalarından birini tıklatırken bu hatayı alırım

+0

Burada * tam * bu kodu diyorsunuz? Görüntüyü, kendi başlığımda yeni bir Thread başlatmayarak, onActivityresult() öğesinde aradığım –

+0

ana iş parçasında işlemediğinizi varsayalım. NDK öğelerinin nasıl ele alındığından emin değil. Neyse NDK bölüm hala çalışıyor (Ben tüm günlükleri ve dosyaları oluşturuldu). Ama sonra iletişim sadece görünmeyecek. Ayrıca işlenmiş görüntüleri göstermek için diyaloga ImageViews ekleyin. CallOnClick() öğesini çağırdığımda Önemli bir hata alıyorum (bazı bellek erişime izin veriyor, izin verilmiyor) – 4ndro1d

+0

"dialog.show()" öğesinin gerçekten ulaşıldığını doğrulayabilir misiniz? –

cevap

2

İletişim kutusunu görüntülemeniz gereken OnActivityResult numaralı bayrağa bir bayrak ayarlamayı deneyin ve bu bayrağı onResume numaralı telefondan kontrol edin, ardından iletişim kutunuzu OnActivityResult yerine orada oluşturun.

Etkinlik yaşam döngüsü yönteminde bir parça işlemi (bu durumda bir iletişim kutusu gösterme) işlemini gerçekleştirmenin neden kötü bir fikir olduğu hakkında daha fazla bilgi için here bulunabilir.

0

Diyaloğunuzu MainActivity uygulamasında görüntülüyorsanız, MainActivity öğenizin ön planda olduğunu belirten bir işaret seçebilirsiniz.

Böyle mümkün olabilir: Sonra

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

, kendi iletişim göstermek bu bayrağı kontrol edin: Bu gibi iletişim oluşturmak için

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

Dene:

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

Yapmak için ivWahetLeft

ImageView ivWahetLeft = (ImageView) dialog.findViewById(R.id.ivWahetLeft); 
İlgili konular