我需要将一个字节数组从一个活动发送到另一个活动。我有这样的事情:
Activity1
-> Activity2
->Activity1
在 Activity2 中,我制作了一张照片,我想将其发送byte[] imageData
到 Activity1 以显示它。为此,在 Activity2 我有:
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c) {
if (imageData != null) {
takephoto=1;
prefsEditor.putInt(TAKEPHOTO, takephoto);
prefsEditor.commit();
System.out.println("imageData in TakePHoto"+ imageData);
Intent mIntent = new Intent();
Bundle b = new Bundle();
b.putByteArray("imageData", imageData);
mIntent.putExtras(b);
setResult(FOTO_MODE, mIntent);
finish();
}
mCamera.startPreview();
mPreviewRunning=true;
}
};
在Activity1
,在OnActivityResult()
我有这个:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
takephoto = myPrefs.getInt(TAKEPHOTO,0);
System.out.println("OnActivityResult"+resultCode);
if (resultCode == RESULT_OK )
if (takephoto == 1){
Toast.makeText(this, "11",Toast.LENGTH_SHORT).show();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 3;
byte[] imageData = data.getByteArrayExtra("imageData");
System.out.println("imageData in Photos"+ imageData );
Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0,
imageData.length, options);
Matrix mat = new Matrix();
mat.postRotate(90);
bitmapResult = Bitmap.createBitmap(myImage, 0, 0, myImage.getWidth(),
myImage.getHeight(), mat, true);
myadapter.notifyDataSetChanged();
}
}
问题是 inActivity1
onActivityResult
没有被调用,我看不出我的错误在哪里。我在 Netbeans 工作,我在 Eclipse 中测试了这段代码,它运行良好。谁能帮我?