Sharing some of the useful snippets of code i stumble across with the world. It will mostly be Android, cloud computing, ColdFusion, SQL, Amazon AWS and other web technologies.
If you like what you read or it helps, drop in a comment and say so, it will be appreciated.

23 December 2013

So this is something in Android I thought would be really simple but quite frankly, wasn't. I want to get a list of all email addresses in my phone and display them in a list. If one is to use ContactsContract.CommonDataKinds.Email.CONTENT_URI without filter you basically get every email address you've ever emailed. Not ideal. I am (in this case) looking for only our saved Google contacts. We can do this query in the UI thread, which works fine but if you have several hundred contacts that'll kill the app. So we're going to use LoaderManager.
First we setup out fragment:

Now we need to setup our createLoader method to get the data and onLoadFinished to put the data into the UI. The selection here is very important as it limits the query to the visible contacts:
String my_selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";. Next step is very simple, in the onLoadFinished we loop through the available data, adding each email address to an ArrayList.