Reputation: 249
I have been googleling but so far no luck. I have an app in which I start an ActivityForResult and in it I put a String extra.
Edit I couldn't post a complex code since I was on my table, I just got on my laptop so here the code
the 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);
}
and for the launching intent
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
}
});
Nothing is passed in value.. it is just null... This is the activityForResult... but in just Activity, I get the passed value.
Upvotes: 0
Views: 100
Reputation: 249
After some well deserved rest, I got my head cleaned and looked at the code... The problem is that I wasn't initializing the output string, thus when puting the extra in the Intent, it was an unset String... Now got it working
Upvotes: 0
Reputation: 83577
You do this to put the value:
i.putExtra("string","value");
Then you do this to get the value:
String value = getIntent().getExtras().getString("value");
The second line should be
String value = getIntent().getExtras().getString("string");
Upvotes: 1