Grokking Android

Getting Down to the Nitty Gritty of Android Development

How to Use Loaders in Android

By

With the introduction of Honeycomb Loaders became the preferred way to access data of databases or content providers. They load data asynchronously and notify listeners when the results are ready. Google did not only introduce Loaders but also deprecated the previous way to handle a Cursor within your activities. You shouldn’t use startManagingCursor() or managedQuery() […]  Continue Reading  “How to Use Loaders in Android”

Android Quick Tip: Enabling and Disabling BroadcastReceivers at Runtime

By

BroadcastReceivers are good when you want to be notified about system events. But sometimes you do need to know about an event only once or for a short period of time. A dynamically registered receiver doesn’t cut it because the Activity and it’s dynamically registered broadcast receiver might long be dead when the event occurs. […]  Continue Reading  “Android Quick Tip: Enabling and Disabling BroadcastReceivers at Runtime”

Recording Audio using Android’s MediaRecorder Framework

By

Sometimes your app needs the ability to record and store audio files. As most devices come with a microphone it’s no surprise that Android offers app developers the possibility to do so. This post deals with the two most common ways to record audio on Android. Recording audio using an Intent As usual that’s by […]  Continue Reading  “Recording Audio using Android’s MediaRecorder Framework”

Adding Files to Android’s Media Library Using the MediaScanner

By

When you add files to Android’s filesystem these files are not picked up by the MedaScanner automatically. But often they should be. As far as I can tell from a cursory search through Android’s codebase, Android runs a full media scan only on reboot and when (re)mounting the sd card. This might sound bad at […]  Continue Reading  “Adding Files to Android’s Media Library Using the MediaScanner”

How to Correctly Store App-Specific Files in Android

By

Christophe Versieux (Waza_be) posted a rant about android developers’ bad habit to store files directly on the root of the sd card. I completely agree with the post. It’s bad usage to create app-specific folders directly at the root. If you install a lot of apps, the sd card’s root gets cluttered fast. One comment […]  Continue Reading  “How to Correctly Store App-Specific Files in Android”

Android Quick Tip: Formatting Text with Html.fromHtml()

By

Android offers you the possibility to easily format text with HTML markup. Thus it’s easy to create text like this: You probably are going to use bold or italics the most, but there are many more supported. Here is the list of all supported tags. You can find it in the source of android.text.Html’s inner […]  Continue Reading  “Android Quick Tip: Formatting Text with Html.fromHtml()”

Android Tutorial: BroadcastReceiver

By

Whenever you want to know about system wide events you need to implement and register a BroadcastReceiver. From then on your receiver gets notifications whenever the system event, for which it is registered, occurs. BroadcastReceivers are one of Android’s four standard components. What are BroadcastReceivers good for? The fact that Android informs you about system […]  Continue Reading  “Android Tutorial: BroadcastReceiver”

Wrapping Your Head Around Android’s Plurals

By

Android has this nice feature to make your handling of strings with numbers easy. If you want to display slightly different messages that depend on how many items a user has selected, you can use Android’s plurals element in your strings.xml: Of course you have to use this string somewhere in your code and you […]  Continue Reading  “Wrapping Your Head Around Android’s Plurals”

Handling Binary Data with ContentProviders

By

To share binary data across app boundaries Android’s programming model expects you to use content providers. And while I have covered how to access content providers and how to code one yourself, I haven’t covered how to deal with binary data. I am going to correct that in this post. How to access binary data […]  Continue Reading  “Handling Binary Data with ContentProviders”

Checking Intent Availability in Android

By

Intents are probably Android’s most powerful tool. They tie together loosely coupled components and make it possible to start Activities that are not part of your own app. Using intents you can delegate to the Contacts app to select a contact or you can start the browser, share data and so on. The receiving apps […]  Continue Reading  “Checking Intent Availability in Android”