Inserting a contact / Android architecture

by brnzn » Thu, 01 Jan 2009 08:06:22 GMT


Sponsored Links
 I have a question on inserting a contact, but it's the general
principle I'm most interested in.  I'd really love to hear from one of
the Android Engineers on this, because currently I find some of the
design decisions in Android perplexing, and I'd like to understand why
it is as it is.

The most direct way to insert a contact seems to be to use
Contacts.People.createPersonInMyContactsGroup(...).  Something like
this:

        ContentValues values = new ContentValues();
        values.put(People.NAME, "Bernie");

        Contacts.People.createPersonInMyContactsGroup(
                        getContentResolver(),
                        values);

We're constructing the person entity as a map.  This brings up a few
potential problems:
1. How do we know what the keys should be?  By convention Android's
own classes (such as People) declare static constants to tell us what
those keys should be, but this is only a convention.
2. How do we know what datatype is appropriate for a given key?
There's nothing to stop you or warn you when you push the wrong type
of data in.
3. How do we know what combination of keys is valid?  If a given
entity has mandatory properties, there's nothing to stop you or warn
you if you forget to set some of those mandatory properties.
4. We're potentially allocating two objects for every value - one for
the value itself and one for the key.  Where we use static constants,
this is less of an issue.

Why does the API not provide a Person object that we can populate and
then pass in to be persisted?  Perhaps something like this:

        Person p = new Person("Bernie");
        p.addGroupMembership("My Contacts");

        getContentResolver().insert(Person.CONTENT_URI, p);

The Person class tells clearly us:
1. What values can be set (by the existence of bean properties)
2. What datatype each property is
3. What values are are mandatory (probably by virtue of them being
required in constructor calls)

Is it a classloading issue?  I'm guessing no because we could easily
overcome that by making Person Serializable or Parcelable, splitting
it out into a JAR to be linked into whatever app needs it.

So what then is the philosophy that has driven the architecture to be
this way?


brnzn

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



Inserting a contact / Android architecture

by Mark Murphy » Thu, 01 Jan 2009 08:45:44 GMT


 


I can't speak for the core Android team, so I cannot say specifically
why they made the design decision.

However, given their repeated insistence that they will not break binary
interfaces with Android OS updates, my guess is that's at least part of
their rationale. The definition of a "contact" has potential to change
significantly. They may feel that a more generic interface will help
them expand the scope of contacts without changing existing uses of the API.

To draw an analogy, it's a variant on the strong-vs.-weak typing
argument you see when Rubyists and Javanauts square off. Strong typing
has definite benefits, in terms of compile-time validations and
potential for optimization. However, strong typing can also "get in the
way", which is why some folk prefer weakly-typed or type-inferred languages.

Anyway, that's my guess. Take it with a grain of salt. Preferably a
large grain of salt, maybe one cubic foot or so... ;-)

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 1.9 Published!

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


Sponsored Links


Other Threads

1. reading package name from apk file

Hello,

If i have a apk file and want to know the package name and class
hierarchy, how do i do it?

Suppose I have some sample APK file named "SampApp.apk" which contains
classes inside "com.android.sampApp".

Is there any tool in Android SDK which shows the package name when APK
file is passed as a parameter.

As the Class files are compressed to dex file I am not able to check
the actual package name.

Regards:
Sudha
--~--~---------~--~----~------------~-------~--~----~

2. audio video rendering in opencore

During media playback, the audio PCM and video YUV data is sent to
audio and video MIO, which then send it to the specific hardware,
which will render it.
Is it like if the data has reached the mio it is ought to be
rendered?
Or there is still a chance of dropping the data.

Any help will be appreciated.

Thanks in advance.

--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. Android: Starting User mode process from kernel mode driver

4. Safely render to bitmap.

5. YAFFS2 filesystem in Android linux?

6. conatct/calender/dialer does not launch

7. how to create a custom listener for some objects..