Using a Loader to get your data out of a database

So what’s a Loader?

loader iconWell, it's the next best thing since sliced bread! This is what they can do for you:

  • You can use loaders in activities and fragments
  • Loaders have been available since Honeycomb (API level 11) and also since Donut (API level 4) if you use the support library
  • Loaders can be used to load any kind of data from any data source (for example, Arrays and Databases)
  • Loaders work on a separate thread so your app carries on working while the Loader gets the data
  • Loaders monitor the data source for any changes and updates the data it gives you
  • Loaders take care of restoring the cursor after a configuration change without having to do a re-query

Accessing the database from another app

Query app iconYou use a content provider to make your database accessible to other apps.

You use a content resolver to access a database in another app.

Using the Content Provider


Using the content provider iconWe covered building our provider class in Part 1. Now in Part 2, we’ll see how we use the provider to access the database.

We will be accessing the database from within the app that created it but we will still use a content resolver to do so.

Building the Content Provider

This is part 1 of creating our custom content provider. This is where we build our ContentProvider class.

Building iconIn part 2, we'll show how we use the provider within the same app to access the database.

Android Content Providers

What you should know about Content providers

Content Provider iconSQLite databases can only be used by the app that created it. However you can choose to share the database with other apps if you wish.

You will need a content provider to manage access to this shared database.

It takes care of data security and communicates between the database and any app wanting to use it.

How to create and use a SQLite database in Android applications

SQLite database iconSo you’ve got this data that you need to save. Why not put it into a SQLite database?

Get the user input: Using TextFields

TextField iconNeed to get user’s names, email addresses, telephone numbers?

In fact you can get the user to enter any text. Just define your fields in your layout. Then when the user touches the field, a keyboard pops up and they can enter the text.

Android Buttons tutorial

Which do you prefer, buttons or zips?

buttons icon

Buttons are part of the app’s user interface.

They allow the user to interact with the app.

The user clicks the button and something happens.

Using Android's Action Bar

Where's the action?

Action Bar iconThe Action Bar

Android Action Bar

The Action Bar is at the top of every activity screen

The app icon displays in it by default.

You can replace the app icon with your company logo if you wish.

You can also include tabs, drop-down lists, pop-ups and menus in the Action Bar.

I’ll show you how to include menu items as Action items in the Action Bar.

Importing Android Studio projects into eclipse

Eclipse import iconYou can’t import Android Studio projects into Eclipse.

Here’s what you can do: