我一直在googleling但到目前为止还没有运气。 我有一个应用程序,我启动一个ActivityForResult,并在其中我添加了一个字符串。
编辑 因为我在桌子上,所以我无法发布复杂的代码,所以我只是在我的笔记本电脑上,所以这里的代码
ActivityForResult:
@Override
protected void onCreate(Bundle saved) {
super.onCreate(saved);
setContentView(R.layout.camera);
a = new AQuery(this);
output = getIntent().getExtras().getString("output");//Here, nothing is passed!!!!!!!!
//Log.d("out",output);
/** Check if this device has a camera */
if (this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)){
text ="yes";
//now we check the cam features
if(this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT))
front ="yes";
if(this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH))
flash = "yes";
if(this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA))
back= "yes";
}else{
text = "This device does not have a camera";
//---set the data to pass back---
data.putExtra("vid",text);
setResult(RESULT_OK, data);
//---close the activity---
finish();
}
if (c != null) {
c.release();
c = null;
}
m = new MediaRecorder();
c = getCameraInstance(this);
Camera.Parameters parameters =
c.getParameters();
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, c);
int orien =getResources().getConfiguration().orientation;
if(orien ==1){
parameters.setRotation(0); // set rotation to save the picture
c.setDisplayOrientation(90);
parameters.setPictureSize(640, 480);
PIC_ORIENTATION = "landscape";
}else{
parameters.setRotation(0); // set rotation to save the picture
c.setDisplayOrientation(0);
parameters.setPictureSize(640, 480);
PIC_ORIENTATION = "portrait";
}
if (Camera.getNumberOfCameras() < 2) {
//TODO
}
fileUri = getOutputMediaFileUri();
c.setParameters(parameters);
m.setCamera(c);
FrameLayout preview = (FrameLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
}
以及启动意图
cam.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent i = new Intent(Mess.this,Cam.class);
i.putExtra("output", vids);
startActivityForResult(i,2);
dialog.cancel();//TODO
}
});
没有传递任何值..它只是空... 这是activityForResult ...但是在Activity中,我得到了传递的值。
答案 0 :(得分:1)
您这样做是为了放置值:
i.putExtra("string","value");
然后执行此操作以获取值:
String value = getIntent().getExtras().getString("value");
第二行应该是
String value = getIntent().getExtras().getString("string");
答案 1 :(得分:0)
经过一些当之无愧的休息之后,我清理了头并查看了代码...问题是我没有初始化输出字符串,因此当把额外的东西放在Intent中时,它是一个未设置的字符串......现在让它工作了