2017-04-26 143 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

相關問題