2017-04-26 346 views
0

当单击屏幕上的按钮时,相机将被打开。关于这个问题,我看到堆栈溢出的帖子很少。我试过finish(),finishActivity(),onBackPressed()方法dispatchTakePictureIntent();onClick方法但是失败!它退出我的整个应用程序。如何返回上一个屏幕上的按下按钮

这是从摘录我full code

巴顿的onClick方法:

mCaptureImage.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Log.d("TAG", "Camera opened"); 
      dispatchTakePictureIntent(); 
     } 
    }); 

此方法调度意图:

private void dispatchTakePictureIntent() { 
     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 = null; 
      try { 
       photoFile = createImageFile(); 
      } catch (IOException ex) { 
       // Error occurred while creating the File 
      } 
      // Continue only if the File was successfully created 
      if (photoFile != null) { 
       photoURI = FileProvider.getUriForFile(this, 
         "com.pc.android.fileprovider", 
         photoFile); 
       takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); 
       startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); 
      } 
     } 
    } 

我的问题是,我怎么回去到前一个屏幕时,当我在C上按下后面的 按钮时amera的意图。

+0

你必须什么也不做。 Android系统会为你处理。 –

+0

但是当我按下相机模块中的按钮时,它会退出我的应用程序。 @NaweenNiroshan – Chip

+0

检查AndroidManifest是否为您的活动设置了android:noHistory =“true”。 –

回答

2
Thus you have to do Nothing : 

你不能覆盖你调用外部活动的方法。 但是,当用户回击使用 startActivityForResult调用的活动时,响应代码RESULT_CANCELLED通常返回 (可能有这种情况不是这样)。在您的 onActivityResult方法简单地检查了RESULT_CANCELLED代码和 调用任何功能,你需要

0

你能尝试使用startActivityForResult和或检查你的onActivityResult被要求回报刊活动的的onResume被称为

+0

@PC有帮助吗? – Aditi

相关问题