0

我有这个问题,我从第一个活动窗口启动第二个活动窗口,我需要直接查看凸轮预览>拍摄快照>在此活动窗口上显示预览。

现在,这就是我需要启动它的方式(用户需求的预期和正确方式),但是在拍照并回到这个窗口之后,应用程序几乎就这样崩溃了。

  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      this.imageView = (ImageView)this.findViewById(R.id.picture);
      Button photoButton = (Button) this.findViewById(R.id.capture_btn);
      //photoButton.setOnClickListener(new View.OnClickListener() {

          //@Override
          //public void onClick(View v) {
              Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
              startActivityForResult(cameraIntent, CAMERA_REQUEST); 
         // }
      //});
  }

但是这样它就不会崩溃,这样它的错误用例就会导致它变成我的应用程序的两个按钮。

public class MainActivity extends Activity  implements OnClickListener {
  private static final int CAMERA_REQUEST = 1888;
  private static final int PIC_CROP = 0; 
  private ImageView imageView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      this.imageView = (ImageView)this.findViewById(R.id.picture);
      Button photoButton = (Button) this.findViewById(R.id.capture_btn);
      photoButton.setOnClickListener(new View.OnClickListener() {

          //@Override
          public void onClick(View v) {
              Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
              startActivityForResult(cameraIntent, CAMERA_REQUEST); 
          }
      });
  }

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {  
        Bitmap photo = (Bitmap) data.getExtras().get("data"); 
        imageView.setImageBitmap(photo);
    }  
  }

  @Override
  public void onClick(View arg0) {
    // TODO Auto-generated method stub

  } 

}
4

0 回答 0