从意图相机或意图库返回时隐藏活动onActivityResult android

时间:2015-09-11 20:13:42

标签: android android-intent camera gallery onactivityresult

我有一个对话框,呼叫“从相机拍摄”或“从画廊中取出”添加新照片,此代码效果很好,我的问题是返回或关闭意图如果拍照或从画廊拍摄图像。我的活动从我称为意图相机和画廊,它隐藏了大约3秒钟并再次显示。我的屏幕数据没有丢失,并显示图像好,我做了所有但没有找到解决方案。重复一遍,打开相机或画廊,拍照和相机完成,当我看到,我的活动隐藏,我的应用程序都隐藏,后来显示。与画廊相同。

这是我的代码:

case 0:
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intent
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
          // Create the File where the photo should go
          File photoFile = createImageFile();

          // Continue only if the File was successfully created
          if (photoFile != null) {
              takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                                    Uri.fromFile(photoFile));
              mUriPhoto = Uri.fromFile(photoFile);
              startActivityForResult(takePictureIntent, TAKE_CAMERA);
           }
     }
     break;
case 1:
     Intent takeGallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
     takeGallery.setType("image/*");
     startActivityForResult(takeGallery, TAKE_GALLERY);
     break;

在这里我的onActivityResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case TAKE_CAMERA:
                ...
                break;
            case TAKE_GALLERY:
                ...
                break;
        }
    }
}

如果有人可以提供帮助,我会很感激。谢谢

0 个答案:

没有答案