2011-12-04 6 views
4

をonActivityResult呼び出していない時々、私は 'OK' を押していたときにアンドロイドACTION_IMAGE_CAPTUREは時々我々はこのようになりますgetPhotoメソッドを使用している私たちのコードでは

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

    Log.w(TAG, "Came"); 

    if (resultCode == RESULT_OK) { 
     if (requestCode == CAPTURE_IMAGE) { 
      try { 
       captureFile = new File(getCaptureFilePath()); 
       captureUri = Uri.fromFile(captureFile); 

       Bitmap scaledBitmap = decodeFileAndResize(captureFile); 
       saveResizedAndCompressedBitmap(scaledBitmap); 

       Bitmap rotatedBitmap = convertToRotatedBitmap(scaledBitmap); 
       driverPhoto.setImageBitmap(rotatedBitmap); 

       Log.w(TAG, "Before recycle"); 

       if (rotatedBitmap != scaledBitmap) { 
        scaledBitmap.recycle(); 
        scaledBitmap = null; 
        System.gc(); 
       } 

       Log.w(TAG, "After recycle"); 
      } catch (IOException e) { 
       BugSenseHandler.log(TAG, e); 
      } 
     } 
    } 
} 

を、 onActivityResultが呼び出されていません(Cameは書きません)。私のコードで何が間違っていますか?

編集:12-04 12:43:36.040: INFO/WindowManager(145): WIN DEATH: Window{40839990 com.skalar/com.skalar.activities.RegisterActivity paused=false}は、onActivityResultが呼び出されていないときに表示されます。

+0

ご覧ください。 http://stackoverflow.com/a/20433752/192373 –

答えて

4

あなたのアクティビティが殺される可能性があります。それがonActivityResultが実行されていない理由ですか?カメラのIntentが返ってくると、通常はonActivityResultに続いてonResumeが実行されます。 onPauseメソッドとonResumeメソッドにlogステートメントを入れ、実行順序を確認します。

+0

カメラが表示されたら(期待通りに)、WIN DEATHが呼び出された後、マニフェスト – skayred

+0

で指定されたように私のスターターアクティビティが呼び出されました。スタックトレースを見て、WIN DEATHを引き起こしたコードを見つけると便利です。いくつかのアイデアについては、これを参照してくださいhttp://stackoverflow.com/questions/6256730/how-to-prevent-my-android-app-from-force-closing – user994886

+0

はい、それは殺されています。今それを克服する方法は? – Yar

2
I faced same problem , once check have you put any tag related to History ? 

アンドロイドを入れないでください:マニフェスト でnoHistory =「true」をタグあなたがアンドロイドを使用する場合:noHistoryマニフェスト内のアクティビティで=「true」を、それが 停止にした後、スタックから削除されます。

注:タブ操作を使用している場合は、android:noHistory = "true" を使用しないでください。そうでない場合はマニフェスト内のアクティビティにアンドロイド:noHistory = "false"を設定してください。

私の説明は間違っているかもしれませんが、私は解決策を得ました。

0

に従って: https://groups.google.com/forum/#!topic/android-developers/aihsOU8uAzU

The method that takes care of the capture only returns correctly 
(using the finnish() method, I think) if the picture can be saved 
correctly in the file specified by that URI. If there's an exception 
(such as an IO exception) it will be captured and nothing will be 
done, so you'll never know. I believe that 'myTestFile' is a file that 
can only be read/written within your own application and that's why 
image_capture can't write to it. 

だから、問題は、あなたがこのメソッドの戻り値captureFileを設定することで、問題を解決することができます

captureFile = new File(getCaptureFilePath()); 
intent.putExtra(MediaStore.EXTRA_OUTPUT, captureUri); 

です:

private File createImageFile() throws IOException { 
     // Create an image file name 
     String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 
     String imageFileName = "JPEG_" + timeStamp + "_"; 
     File directory = new File(Environment.getExternalStoragePublicDirectory(
      Environment.DIRECTORY_PICTURES), "your subdirectory for Picture directory"); 
     if(!directory.exists() && !directory.mkdir()) 
      return null; 
     File image = File.createTempFile(
       imageFileName, /* prefix */ 
       ".jpg",   /* suffix */ 
       directory  /* directory */ 
     ); 

     // Save a file: path for use with ACTION_VIEW intents 
     return image; 
    } 
関連する問題