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(..)

Example:

  setResult(RESULT_OK, (new Intent()).setAction("Corky!"));
and
  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();
  mIntent.putExtras(bundle);
  setResult(RESULT_OK, mIntent);

I believe that the NotesList.java is the only one which does it
correctly.

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 ReceiveResults.java should have also called
putExtra(..):
  setResult(RESULT_OK, (new Intent()).putExtra(NAME, "Violet!"));

NoteEditor.java should have used putExtra(..):
  setResult(RESULT_OK, (new Intent()).putExtra(NAME,
mUri.toString()));
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: 
 http://spencer.riddering.net/2008/8/21/inconsistent-usage-setresult-intent 
--~--~---------~--~----~------------~-------~--~----~



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. Rotate animation applied to full window -- view crops width? How to fix?

Hi all,

I have a pretty simple view hierarchy, including an ImageView in a
FrameLayout with a source drawable that is bigger than the window
size.  Using scaleType=center the image is cropped and centered, as
expected, when laid out.

In response to user interaction we need to rotate the ImageView.  I am
using a rotate animation XML definition and View.startAnimation().
This works with one remaining problem: the cropped part of the image
remains cropped when rotated, so when the image is rotated by 90
degrees in portrait orientation the image is clearly cropped on the
top and bottom.  Essentially it looks like a rectangle the size of the
view window is being rotated, rather than the oversized image in its
entirety (note it is intentionally oversized in the hope of avoiding
this cropping problem).  We want the image to fill the screen
regardless of the angle of rotation.

What am I missing?

Thanks in advance for any assistance!

-- 

2. Android Eclair porting on Beagleboard Omap3530 Init problem when booting

I get it from :

repo init -u git://
labs.embinux.org/embinux-android-build/android-omap3/repo/android/platform/manifest.git-b
beagle-eclair



2009/12/19 AbeOwitz <abeow...@gmail.com>

> website: 

3. Only onCreate and no onRestart after startActivity ! Please Help

4. Sip voip apps for android: Is sipdroid the only joice?

5. setting spinner selection based on strings

6. Featured Apps on the market vever change!!!

7. how can resource xml will be changed in runtime..