Difference between revisions of "MAP524/DPS924 Lecture 8"

From CDOT Wiki
Jump to: navigation, search
(Created page with '= Content Providers = This week we're looking at another means of sharing data between Android apps, this one is usually used for well structured data with a stable API for acce…')
 
(A look back at Intents)
Line 10: Line 10:
  
 
To get data back from an activity you started you need to use startActivityForResult() instead of startActivity(), [http://developer.android.com/intl/ja/reference/android/app/Activity.html#StartingActivities see here] for an explanation and example.
 
To get data back from an activity you started you need to use startActivityForResult() instead of startActivity(), [http://developer.android.com/intl/ja/reference/android/app/Activity.html#StartingActivities see here] for an explanation and example.
 +
 +
== Using an existing content provider ==
 +
 +
Android ships with many useful content providers, including the following:
 +
* Browser - Stores data such as browser bookmarks, browser history, and so on
 +
* CallLog - Stores data such as missed calls, call details, and so on
 +
* Contacts - Stores contact details
 +
* MediaStore - Stores media files such as audio, video, and images
 +
* Settings - Stores the device ’ s settings and preferences
 +
 +
The [http://developer.android.com/intl/ja/guide/topics/providers/content-provider-basics.html Content Provider Basics] tutorial is a little verbose and scary, but that's kind of unavoidable with overdesigned nonsense like this.
 +
 +
One note about using content providers: there used to be a slightly simpler way to query them using managedQuery() but that function has been deprecated so you shouldn't use it in new code.

Revision as of 19:44, 2 August 2015

Content Providers

This week we're looking at another means of sharing data between Android apps, this one is usually used for well structured data with a stable API for accessing it. But first..

A look back at Intents

Most of you have only used an intent to start an activity, and haven't thought much about the Intent object. Today let's use a couple of features available with an intent, specifically for passing data to the activity being started and getting data back from it.

This tutorial is pretty good, it talks about how to use the Intent to pass data to and receive it in an Activity. Android Studio autocomplete will help you see what other types of data you can pass.

To get data back from an activity you started you need to use startActivityForResult() instead of startActivity(), see here for an explanation and example.

Using an existing content provider

Android ships with many useful content providers, including the following:

  • Browser - Stores data such as browser bookmarks, browser history, and so on
  • CallLog - Stores data such as missed calls, call details, and so on
  • Contacts - Stores contact details
  • MediaStore - Stores media files such as audio, video, and images
  • Settings - Stores the device ’ s settings and preferences

The Content Provider Basics tutorial is a little verbose and scary, but that's kind of unavoidable with overdesigned nonsense like this.

One note about using content providers: there used to be a slightly simpler way to query them using managedQuery() but that function has been deprecated so you shouldn't use it in new code.