views:

42

answers:

3

Hi,

I hope the title says it all: I've got Activity A which fires up the Camera intent via:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, REQUEST_CAMERA);

After the picture is taken I can easily grab the picture in:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)

But I'd like to receive the result in Activity B in which the image can be edited. Right now I'm receiving the result in Activity A and pass it over to Activity B which results in showing the GUI of Activity A for a short while:

Intent i = new Intent().setAction("DisplayJPEG");
i.setClass(this, EditImageActivity.class);
i.putExtra("IMAGE_URI", uri);
startActivityForResult(i, REQUEST_EDIT_IMAGE);

Of course, I will need the result from Activity B in Activity A after the image has been edited. But that should work with:

setResult(resultCode, data);

So there has to be a way to do what I need. Please point me into the right direction.

Thanks in advance, steff

+2  A: 

Have you tried launching ActivityB, and in ActivityB onCreate event launch the Camera Intent?

Pentium10
no, I haven't tried that, yet. Looks like an ugly solution. But what I've learned from you guys this seems to be the only solution. Never saw that coming...Thanks guys
steff
This sounds like it is the way to go if you control activity B. Make you intent start Activity B, then get Activity B to open up the camera, process the image and send it back to Activity A as a result.
Janusz
This is similar in other languages to launch ShowModal in a Constructor. Hope this helps. I use it frequently.
Pentium10
You are right, launching the camera intent in ActivityB onCreate does the trick. No UI of ActivityB is drawn since we are in onCreate so you just fire up the camera app, catch its result, store it via setResult(Intent i) and finish ActivityB. Nice
steff
+1  A: 

You technically can't do what you're asking. You'll need to find a way to continue passing it the way you are and hide the UI or do as Pentium says and do it the other way around.

Scott Main
+1  A: 

Edit: Nevermind, I misread how this works. What actually happens is you can use Activity A to start Activity B for result, but then if Activity B needs to start Activity C to continue processing whatever Activity A wanted, you can use FLAG_ACTIVITY_FORWARD_RESULT to make Activity C return its result to Activity A not B.


I haven't looked into this more than a quick glance, but I noticed an Intent flag called FLAG_ACTIVITY_FORWARD_RESULT which according to the documentation:

If set and this intent is being used to launch a new activity from an existing one, then the reply target of the existing activity will be transfered to the new activity. This way the new activity can call setResult(int) and have that result sent back to the reply target of the original activity.

Like I said, I haven't experimented with this, but that seems to suggest that you could launch your camera intent from Activity A but have it forward its result to Activity B.

Steve H
I don't think this will work since you cannot influence the intent created by the built-in camera app.
steff
Yes, that's what I meant by the edit to my comment - I realised it wasn't going to work.
Steve H