不调用OnActivityResult()

时间:2013-09-20 07:38:43

标签: android android-intent

当控制转到Samsung Galaxy Ace(Android版本2.3.6)上的firstActivity时,不会调用OnActivityResult(),但它适用于Samsung galaxy fit(Android版本2.3.6)。请帮帮我......

以下是我的代码:

在第一项活动中

Intent intent = new Intent(this,CameraActivity.class);
        startActivityForResult(intent, 2);



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

        super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK) { 

          photo =  data.getByteArrayExtra("image_data");

        Bitmap bitmap = BitmapFactory.decodeByteArray(photo ,0,photo.length);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG,75, bos);
        data1 = bos.toByteArray();
        bab = new ByteArrayBody(data1, ""+ ConsumerNo.getText() +".JPEG");
    }

}

在第二项活动中:

@Override
    public void onPictureTaken(byte[] data, Camera camera) {



        data1 = data;
        if(data1 == null)
        {
            Log.d("==========>>>>>", "nuuullllllllllllll");
        }
        FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
        preview.setVisibility(View.GONE);
        Button captureButton = (Button) findViewById(R.id.button_capture);
        captureButton.setVisibility(View.GONE);
        imageView = (ImageView)findViewById(R.id.imageView1);
        saveButton=(Button) findViewById(R.id.saveBtn);
        newButton=(Button) findViewById(R.id.newBtn);
        imageView.setVisibility(View.VISIBLE);
        saveButton.setVisibility(View.VISIBLE);
        newButton.setVisibility(View.VISIBLE);


        ImageView imageBut= (ImageView)findViewById(R.id.imageView1);
        bitmap = BitmapFactory.decodeByteArray(data , 0, data .length);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bitmap.compress(CompressFormat.JPEG,75, bos);
        imageBut.setImageBitmap(bitmap);
        saveButton.setOnClickListener(CameraActivity.this);


        newButton.setOnClickListener(CameraActivity.this);

    }


         if(((Button)v).getId() == saveButton.getId())
    {
        intent = getIntent();

        intent.putExtra("image_data", data1);
        setResult(RESULT_OK, intent);

        finish();
    }

1 个答案:

答案 0 :(得分:0)

你应该做一个switch case语句来处理requestCodes。

在这种情况下,请执行以下操作:

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

  super.onActivityResult(requestCode, resultCode, data);

  switch(requestCode){

  case 2: //2 since you started your intent with 2 as the requestCode
    if  (resultCode == RESULT_OK) { 
         //your code here
    }
    break;
  }

}