1 00:00:00,000 --> 00:00:04,929 [MUSIC] 2 00:00:04,929 --> 00:00:08,975 Hello I'm Ben and I'd like to help you be a better communicator. 3 00:00:08,975 --> 00:00:12,190 Well what I mean is I'd like to get you better at sharing. 4 00:00:12,190 --> 00:00:13,680 Wait that's not right. 5 00:00:13,680 --> 00:00:14,770 Let's try this again. 6 00:00:14,770 --> 00:00:18,290 I'd like to show you how to share data in Android in ways that 7 00:00:18,290 --> 00:00:21,750 seamlessly integrate your apps with other apps in the Android system. 8 00:00:23,980 --> 00:00:26,260 Listen, communication is hard. 9 00:00:26,260 --> 00:00:29,330 Lucky for us though, communication in Android is pretty easy 10 00:00:29,330 --> 00:00:31,430 thanks to a wonderful invention called Intents. 11 00:00:31,430 --> 00:00:35,780 You're hopefully pretty familiar with the concept of Intents at this point. 12 00:00:35,780 --> 00:00:39,220 If not, I'd urge you to check the teacher's notes for prerequisites and 13 00:00:39,220 --> 00:00:42,230 related material here at Treehouse that you should check out. 14 00:00:42,230 --> 00:00:43,805 We'll review all the basics, but 15 00:00:43,805 --> 00:00:46,410 we'll also dive deeper and look at special cases. 16 00:00:46,410 --> 00:00:48,860 So don't worry if at first this feels like stuff you already know. 17 00:00:48,860 --> 00:00:53,530 All right, so let's review what we do know about Intents. 18 00:00:53,530 --> 00:00:55,440 The name itself is a big clue, 19 00:00:55,440 --> 00:00:59,990 the Android Intents are objects that we can use to express our intentions. 20 00:00:59,990 --> 00:01:05,930 For example, when we intend to start a new activity or service, we create an Intent 21 00:01:05,930 --> 00:01:10,500 or maybe we intend to share some data in another app like Facebook or WhatsApp. 22 00:01:10,500 --> 00:01:13,980 We use Intents in that case too but we configure them a little bit differently. 23 00:01:15,810 --> 00:01:20,150 The thing to remember is that Intents are all about passing information around. 24 00:01:20,150 --> 00:01:23,070 We can pass all sorts of data, in all sorts of ways. 25 00:01:23,070 --> 00:01:28,180 Text, dates, images, complex data models, Intents can handle it all. 26 00:01:28,180 --> 00:01:32,910 And we can use Intents to communicate to all sorts of things in the Android system. 27 00:01:32,910 --> 00:01:36,430 Inside of our own app we can share data from one activity to another, 28 00:01:36,430 --> 00:01:40,210 from an activity to a service, or from a service back to an activity. 29 00:01:40,210 --> 00:01:44,090 But it doesn't end there, we can also use Intents to share data with another app or 30 00:01:44,090 --> 00:01:47,180 to broadcast it system-wide. 31 00:01:47,180 --> 00:01:49,530 We can also listen for system-wide broadcasts. 32 00:01:49,530 --> 00:01:52,400 Let's say we're working on an app that can handle phone calls. 33 00:01:52,400 --> 00:01:55,340 The system takes care of the low-level details of sending and 34 00:01:55,340 --> 00:01:56,800 receiving phone calls. 35 00:01:56,800 --> 00:02:00,400 But it broadcasts the data about a call in a way that we can listen for and 36 00:02:00,400 --> 00:02:01,860 do something about. 37 00:02:01,860 --> 00:02:05,230 We listen for these system wide broadcasts using something called 38 00:02:05,230 --> 00:02:07,250 a broadcast receiver. 39 00:02:07,250 --> 00:02:09,890 We have a great example app to work from here. 40 00:02:09,890 --> 00:02:13,130 You may have worked on the MusicMachine app in a previous course. 41 00:02:13,130 --> 00:02:16,720 But if not, don't worry, we're going to download a new version in the next video 42 00:02:16,720 --> 00:02:19,050 that contains a few minor new things. 43 00:02:19,050 --> 00:02:22,070 This app plays a simple song using a background service but 44 00:02:22,070 --> 00:02:24,780 we will extend it to demonstrate these different ways of sharing data. 45 00:02:24,780 --> 00:02:29,530 We're going to work our way through this list of examples. 46 00:02:29,530 --> 00:02:31,750 We already know how to do some of these types of sharing. 47 00:02:31,750 --> 00:02:34,760 But we'll review those and then pave our way forward with new examples. 48 00:02:36,230 --> 00:02:40,730 Notice that device to device communication was left off of that list. 49 00:02:40,730 --> 00:02:44,920 That requires sending data over the network and either pulling it from or 50 00:02:44,920 --> 00:02:47,020 pushing it to another device. 51 00:02:47,020 --> 00:02:49,480 That's beyond the scope of this course but check the teachers notes for 52 00:02:49,480 --> 00:02:50,160 more information. 53 00:02:51,330 --> 00:02:53,340 All right it's time to get started. 54 00:02:53,340 --> 00:02:55,330 I intend to have lots of fun. 55 00:02:55,330 --> 00:02:55,910 It's going to be great.