1 00:00:00,000 --> 00:00:04,499 [MUSIC] 2 00:00:04,499 --> 00:00:09,810 Hi, I'm Ben and in this workshop we're going to learn about content providers. 3 00:00:09,810 --> 00:00:14,710 A content provider is basically just an interface for working with a dataset. 4 00:00:14,710 --> 00:00:18,880 You can think of it as a middleman between your app and its data. 5 00:00:18,880 --> 00:00:23,610 Unfortunately, content providers get kind of a bad rap but it's not their fault. 6 00:00:23,610 --> 00:00:25,390 They're just misunderstood. 7 00:00:25,390 --> 00:00:29,580 You see, content providers were created to allow apps to share their data with 8 00:00:29,580 --> 00:00:30,940 other apps. 9 00:00:30,940 --> 00:00:34,300 So if you don't plan on sharing your data with other applications, 10 00:00:34,300 --> 00:00:36,470 you don't need to use a content provider. 11 00:00:36,470 --> 00:00:40,730 Which means that almost all apps don't need to use a content provider. 12 00:00:40,730 --> 00:00:43,230 And I think that's what makes them seem so difficult. 13 00:00:43,230 --> 00:00:46,210 There's a lot of folks who get the idea that they should be using a content 14 00:00:46,210 --> 00:00:49,620 provider when really they'd be fine with a local database or 15 00:00:49,620 --> 00:00:50,680 even just shared preferences. 16 00:00:51,740 --> 00:00:55,870 That said, there are a few places where content providers can come in handy. 17 00:00:55,870 --> 00:01:00,260 In fact, the Android system itself makes use of a bunch of content providers. 18 00:01:00,260 --> 00:01:04,050 Your alarms, contacts and even your calendar are all available to 19 00:01:04,050 --> 00:01:07,010 other applications through content providers. 20 00:01:07,010 --> 00:01:11,120 In the case of alarms, the Android system has an app that stores all the data for 21 00:01:11,120 --> 00:01:12,290 your alarms. 22 00:01:12,290 --> 00:01:15,790 And that app has a content provider to make that data accessible to 23 00:01:15,790 --> 00:01:17,320 other applications. 24 00:01:17,320 --> 00:01:23,080 This way app developers like us can write apps to access that data and set alarms. 25 00:01:23,080 --> 00:01:27,770 So we might have multiple alarm apps, but they're all looking at the same data. 26 00:01:27,770 --> 00:01:30,540 And that's what makes content providers so powerful, 27 00:01:30,540 --> 00:01:34,710 they give us a way to have a common dataset across multiple applications. 28 00:01:34,710 --> 00:01:37,370 For this workshop, we're going to make a new content provider 29 00:01:37,370 --> 00:01:41,160 to keep track of our VICs, very important contacts. 30 00:01:41,160 --> 00:01:44,660 It will be kind of like the already existing contacts provider 31 00:01:44,660 --> 00:01:49,020 except this one will only have very important contacts. 32 00:01:49,020 --> 00:01:52,630 In order to focus on content providers, we're going to start with an already built 33 00:01:52,630 --> 00:01:56,270 app that uses a SQL like database to store the VICs. 34 00:01:56,270 --> 00:01:59,448 So if you're not familiar with SQL, you might want to check out some of the links 35 00:01:59,448 --> 00:02:01,900 in the teacher's' notes before we get started. 36 00:02:01,900 --> 00:02:02,960 And on that note, 37 00:02:02,960 --> 00:02:05,740 join me in the next video to start diving into content providers.