Inconsistent usage of setResult(..) Intent.

by Spencer Riddering » Thu, 21 Aug 2008 13:22:28 GMT

Sponsored Links
 It appears that the example applications from version 0.9 and the
migration tips are not consistent in their usage of the Intent that is
passed to setResult(..)


  setResult(RESULT_OK, (new Intent()).setAction("Corky!"));
  setResult(RESULT_OK, (new Intent()).setAction("Violet!"));

  setResult(RESULT_OK, (new Intent()).setAction(mUri.toString()));

  setResult(RESULT_OK, new Intent().setData(uri));

  Bundle bundle = new Bundle();
  bundle.putString(TEST_STRING, "Corky!");
  Intent mIntent = new Intent();
  setResult(RESULT_OK, mIntent);

I believe that the is the only one which does it

I'm not sure why "M5 to 0.9 porting and migration tips" bothers with
the Bundle. Isn't it more straight forward to just call
mIntent.putExtra(TEST_STRING, "Corky!");   ?

I think that should have also called
  setResult(RESULT_OK, (new Intent()).putExtra(NAME, "Violet!")); should have used putExtra(..):
  setResult(RESULT_OK, (new Intent()).putExtra(NAME,
or better yet, it should have used the setData(..) method:
  setResult(RESULT_OK, (new Intent()).setData(mUri));

Many of these inconsistent usages stem from attempting to replace the
setResult(..) String parameter with the setAction(..) method's String.
IMHO, this hijacking of setAction(..) corrupts the clear purpose of
the Action String and so should be avoided.

Do I have it right? Am I missing something?

I'm interested in other people's take on this ambiguity because I see
it as an impediment to seamless integration between applications.

Originally blogged at: 

Inconsistent usage of setResult(..) Intent.

by hackbod » Tue, 26 Aug 2008 00:19:43 GMT

 There is not really a "correct way."  There is no direct mapping
between the old arguments and the new ones -- you can structure your
data in the Intent as you want.  Generally you should follow the same
conventions as used elsewhere for Intents.

If this Intent is not going to travel outside of your app, it really
doesn't matter how you structure it.  If it is going between apps,
more thought should be put into it, and the NotePad example is a good
one to follow.  Note that the ApiDemo example is very artificial,
those results don't -mean- anything, so there isn't a strong
convention to use.


Sponsored Links

Other Threads

1. sdcard problem

Hi, All

I have made new system.img, actually just download the source and make
So, I am trying to upgrade my dev phone with new system.img using
fastboot process.
And Copying the system.img looks fine but the dev phone can't detect
the sdcard.

Am I wrong? or Is there more process I should do.?

2. Moving data from Phone to PC

I am developing an Android application that collects accelerometer
sensor readings. I need to somehow get this data from the phone to a
desktop computer.  I want to have a "Send" button that sends the data.

The closest I have come is that if put the data in the image Content
Provider and say it's a jpeg (it's not), then I can email that as an
attachment from gmail.

But that is not an acceptable thing to ask users to do.



3. Vibrating Notifications

4. Problem with Displaying Web Server's Response (Text) in Android

5. problem starting emulator from command line

6. Google Maps with geo Intent

7. Starting Google Maps from my Activity