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. Surface formats vs. Bitmap formats

Hi all,  I'm creating Bitmaps to draw in a surface.  I want to do the
right thing and handle as many Surface pixel formats as I can, while
creating the Bitmap format that will be most efficient for that
Surface.

So I'm wondering how to reconcile these formats:

                Bitmap.Config config = null;
                switch (format) {
                case PixelFormat.A_8:
                        config = Bitmap.Config.ALPHA_8;
                        break;
                case PixelFormat.RGBA_4444:
                        config = Bitmap.Config.ARGB_4444;
                        break;
                case PixelFormat.RGBA_8888:
                        config = Bitmap.Config.ARGB_8888;
                        break;
                case PixelFormat.RGB_565:
                        config = Bitmap.Config.RGB_565;
                        break;
                default:
                        break;
                }

How come Surface is RGBA while Bitmap is ARGB?  Is the mapping I use
above the best one?

Cheers

--~--~---------~--~----~------------~-------~--~----~

2. Samsung phone for 2009Q2 in North America

http://english.etnews.co.kr/news/detail.html?id=200812190010

-- 
======
Funky Android Limited is registered in England & Wales with the 
company number  6741909. The registered head office is Kemp House, 
152-160 City Road, London,  EC1V 2NX, UK. 

The views expressed in this email are those of the author and not 
necessarily those of Funky Android Limited, it's associates, or it's 
subsidiaries.


--~--~---------~--~----~------------~-------~--~----~

3. Replacing default Menu with a Dialog

4. G1 owners: "A system update is available" - is it safe?

5. Getting Starting Guide for Android Dev Phone missing.

6. android dns problems

7. How To Eliminate Preferences Values Database?