• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

My phone has only 2 contacts, but when I query for them I get 5, how can this be?

 
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm experimenting with Android, using eclipse, ADT, and the emulator

On the emulator, I have programmed in 2 contacts.

However, if I query for my contacts using the code below, I get 5 back, how can this be?!



(MeCercanaContact is a POJO, just 2 strings with accessors, nothing fancy)

output is :



I've cross-posted this on StackOverflow : http://stackoverflow.com/questions/3588585/android-i-only-have-2-contacts-yet-i-can-obtain-5-from-a-query-why

It seems that the cursor has a count of 5, I'm really baffled as to why. I've been through the tutorials on the android site, and thought I had the hang of it, clearly I was mistaken
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Data content provider returns individual rows related to a record. Basically if you have a contact with a name, a phone number, and an email address, then the Data content provider will return 3 rows for that contact. The Data content provider returns some data for the record and its type (like Phone.CONTENT_ITEM_TYPE or Email.CONTENT_ITEM_TYPE). If you want to extract specific information about a contact like a phone number or address, then you'll have to constraint the returned rows to only those type of records using the where clause of the content provider (some examples are given here)...
 
James Elsey
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit,

I think I'm partially with you on this one. I understand that for each piece of data, you will get an individual row, and since I have stored the following :

name of James Elsey
name of Dave Smith
postcode for James elsey
postcode for Dave smith
phone number for James Elsey

Then that equates to 5 separate pieces of data, so that makes sense.

My confusion is your suggestion of using a where clause. I've looked at the examples you linked but I can't see how they will help. The examples use a contactID in the where clause to limit the results to a single contact, I don't want this

How can I get the fields for each contact, to have 2 rows in the cursor, so I can process each row individually (such as populating my POJO)?
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to get individual information about all contacts like phone numbers or email addresses or postal addresses, you can use separate content providers. Like to get phone numbers you can use Phone provider, to get email addresses, you can use Email provider and to get postal address, you can use StructuredPost provider. Again for all these content providers, there can be multiple rows for the same person, like if a person has a home phone no. and a work phone no, the phone provider will return 2 rows for one person...
 
James Elsey
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand that I will need to do different queries, but I'm stuck at an initial stage.

I'm thinking I will have to do the following

Obtain list of unique contact IDs
Loop through each contact ID, running separate queries for email, postal, phone etc

However, I can't get a list of unique contact IDs

Using the following gives me duplicates



Please help me, I can sense I am close to resolving this issue
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I provided you with a link to a tutorial in your other topic which is this tutorial. If you go through it, you'll know that to get a list of Contact IDs, you'll need to query the Contacts provider...
 
James Elsey
Ranch Hand
Posts: 231
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ankit

Clearly I missed something the first time I went through that tutorial, going over it again has cleared it up

Cheers
 
The longest recorded flight time of a chicken is 13 seconds. But that was done without this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic