when onActivityResult is called?

Put your problem here if it does not fit any of the other categories.

when onActivityResult is called?

Postby Premier » Fri Jul 31, 2009 10:51 pm

Hello all,
I'm new to Android development, and am a bit confused here. I'm
hoping someone can help me out. Please forgive me as I cross post
this to android-developers - I tried on android-begginers last week
but got no response.

Anyway, I've got a very simple Activity with one EditText and one Button.
Lets call it MyActivity. Now, when I click on the button on
MyActivity, I want to take a picture using the camera. For the sake
of this e-mail, lets call the activity that gets spawned when I click
on the button CameraActivity.

Here is how I've setup my button:

Button takePictureButton = (Button)
takePictureButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ContentValues values = new ContentValues();
values.put(Media.TITLE, "IMAGE");
values.put(Media.DESCRIPTION, "Image
Captured by Camera");
Uri uri =
getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
Intent i = new
i.putExtra("output", uri);

As I understand it, click the button will cause MyActivity to start up
CameraActivity, which is just the default camera application, to take
a picture. Because I've used startActivityForResult, when
CameraActivity finishes, MyActivity should be notified via it's
onActivityResult. Below is how I've coded it up:

I've defined my onActivityResult as follows:

protected void onActivityResult(int requestCode, int
resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
Log.d(TAG, "WOW!");

So, what has me confused is this: I would expect onActivityResult to
be called AFTER I take a picture, i.e. when I click on the picture
button. Instead, it seems to get called immediately: I click on the
takeAPictureButton, the camera activity starts up at about the same
time the code in onActivityResult gets fired. Am I missing something
Junior Developer
Junior Developer
Posts: 21
Joined: Fri Jul 10, 2009 4:04 pm


Postby burujo » Wed Oct 14, 2009 2:53 pm

Hey, I'm having the same problem.

I notice that my "onActivityResult" is being called at the same time that the other activity starts.

Anybody has an idea to avoid this?
Posts: 4
Joined: Thu Mar 26, 2009 1:32 am

Postby burujo » Thu Oct 15, 2009 3:31 am

I solved my problem.

In my case the error were that i've put the code that will use the result just after calling the other activity, but I should have put this code in the OnActivityResult().

Premier, have you solved your problem?
Posts: 4
Joined: Thu Mar 26, 2009 1:32 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 20 guests