Introducing Content Providers2:06 with Ben Deitch
In this video we'll learn what Content Providers are and when to use them!
[MUSIC] 0:00 Hi, I'm Ben and in this workshop we're going to learn about content providers. 0:04 A content provider is basically just an interface for working with a dataset. 0:09 You can think of it as a middleman between your app and its data. 0:14 Unfortunately, content providers get kind of a bad rap but it's not their fault. 0:18 They're just misunderstood. 0:23 You see, content providers were created to allow apps to share their data with 0:25 other apps. 0:29 So if you don't plan on sharing your data with other applications, 0:30 you don't need to use a content provider. 0:34 Which means that almost all apps don't need to use a content provider. 0:36 And I think that's what makes them seem so difficult. 0:40 There's a lot of folks who get the idea that they should be using a content 0:43 provider when really they'd be fine with a local database or 0:46 even just shared preferences. 0:49 That said, there are a few places where content providers can come in handy. 0:51 In fact, the Android system itself makes use of a bunch of content providers. 0:55 Your alarms, contacts and even your calendar are all available to 1:00 other applications through content providers. 1:04 In the case of alarms, the Android system has an app that stores all the data for 1:07 your alarms. 1:11 And that app has a content provider to make that data accessible to 1:12 other applications. 1:15 This way app developers like us can write apps to access that data and set alarms. 1:17 So we might have multiple alarm apps, but they're all looking at the same data. 1:23 And that's what makes content providers so powerful, 1:27 they give us a way to have a common dataset across multiple applications. 1:30 For this workshop, we're going to make a new content provider 1:34 to keep track of our VICs, very important contacts. 1:37 It will be kind of like the already existing contacts provider 1:41 except this one will only have very important contacts. 1:44 In order to focus on content providers, we're going to start with an already built 1:49 app that uses a SQL like database to store the VICs. 1:52 So if you're not familiar with SQL, you might want to check out some of the links 1:56 in the teacher's' notes before we get started. 1:59 And on that note, 2:01 join me in the next video to start diving into content providers. 2:02
You need to sign up for Treehouse in order to download course files.Sign up