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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---