1 00:00:00,160 --> 00:00:04,160 (upbeat music and keys tapping) 2 00:00:05,040 --> 00:00:08,170 Before I move on, many new programmers struggle 3 00:00:08,170 --> 00:00:11,583 with this idea that something can be of more than one type. 4 00:00:12,560 --> 00:00:16,000 So looking at it AddEditFragment on line 30 5 00:00:16,000 --> 00:00:17,340 you can see that we've declared listener 6 00:00:17,340 --> 00:00:19,400 to be an unsafe clicked object 7 00:00:19,400 --> 00:00:20,790 and that means that it's guaranteed 8 00:00:20,790 --> 00:00:23,070 to implement the interface and can be used 9 00:00:23,070 --> 00:00:26,460 whenever an object of type unsafe clicked is needed. 10 00:00:26,460 --> 00:00:29,160 But any class can implement the interface. 11 00:00:29,160 --> 00:00:32,130 Objects of that class can then be of type unsafe clicked, 12 00:00:32,130 --> 00:00:35,200 but they still have the base type of their class. 13 00:00:35,200 --> 00:00:37,603 So we get past the activity in onAttach, 14 00:00:38,762 --> 00:00:40,880 down here on line 60. 15 00:00:40,880 --> 00:00:42,150 But it's pathed so you can see 16 00:00:42,150 --> 00:00:44,700 it is an object of type context. 17 00:00:44,700 --> 00:00:46,240 Because our activity implements 18 00:00:46,240 --> 00:00:48,709 the OnClickListener interface we can 19 00:00:48,709 --> 00:00:51,810 assign the reference to it, to Listener . 20 00:00:51,810 --> 00:00:54,220 That doesn't alter what the object was 21 00:00:54,220 --> 00:00:55,470 it just means that we can use it 22 00:00:55,470 --> 00:00:57,760 in place of OnClickListener. 23 00:00:57,760 --> 00:01:00,579 It's also still a context and it's also 24 00:01:00,579 --> 00:01:03,480 an AppCompatActivity and the reason for that 25 00:01:03,480 --> 00:01:04,680 is that's because what we've declared 26 00:01:04,680 --> 00:01:07,080 our activity to be, back here, 27 00:01:07,080 --> 00:01:08,797 in our declaration of main activity, 28 00:01:08,797 --> 00:01:11,430 you'll see that on line 17. 29 00:01:11,430 --> 00:01:13,280 It's also still a context 30 00:01:13,280 --> 00:01:15,263 and it's also an AppCompatActivity. 31 00:01:16,230 --> 00:01:17,300 Alright, so you might be wondering 32 00:01:17,300 --> 00:01:19,620 how it can also be a context. 33 00:01:19,620 --> 00:01:21,900 So if we control click 34 00:01:21,900 --> 00:01:24,553 or command click on AppCompatActivity, 35 00:01:26,300 --> 00:01:28,600 depending on your version of Android Studio, 36 00:01:28,600 --> 00:01:31,800 and whether Google have fixed the source code 37 00:01:31,800 --> 00:01:33,310 you may get this or you might get 38 00:01:33,310 --> 00:01:34,620 directly to the source code, 39 00:01:34,620 --> 00:01:38,030 in any event you can click on accept if you get this, 40 00:01:38,030 --> 00:01:39,510 and we'll still get to see the code anyway, 41 00:01:39,510 --> 00:01:41,810 at the moment because of the way Android SDK 42 00:01:41,810 --> 00:01:43,980 has been updated Google haven't got 43 00:01:43,980 --> 00:01:48,580 the sources working for version 28 of the Android SDK, 44 00:01:48,580 --> 00:01:49,660 and that's the reason why 45 00:01:49,660 --> 00:01:52,460 the decompiler's kicked in automatically. 46 00:01:52,460 --> 00:01:54,370 Alright so moving on though, 47 00:01:54,370 --> 00:01:55,990 we come down here to the declaration 48 00:01:55,990 --> 00:01:59,050 for AppCompatActivity, you can see here, 49 00:01:59,050 --> 00:02:01,170 that it extends fragment activity 50 00:02:01,170 --> 00:02:02,610 so that means our main activity 51 00:02:02,610 --> 00:02:05,730 can also be used where fragment activity's needed. 52 00:02:05,730 --> 00:02:07,930 So let's now see what fragment activity is, 53 00:02:07,930 --> 00:02:09,773 by control or command clicking it. 54 00:02:11,950 --> 00:02:14,000 So on the current API 20 at source, 55 00:02:14,000 --> 00:02:17,080 you can see that that's extending support activity. 56 00:02:17,080 --> 00:02:19,030 If you're targeting API 27 by the way 57 00:02:19,030 --> 00:02:22,090 it extends base fragment activity API 16 58 00:02:22,090 --> 00:02:23,860 but the principle is still the same. 59 00:02:23,860 --> 00:02:25,640 You'll find a lot of inheritance like this 60 00:02:25,640 --> 00:02:28,080 by the way when using the support libraries. 61 00:02:28,080 --> 00:02:30,060 Right so let's keep going here, let's click on, 62 00:02:30,060 --> 00:02:32,160 control or command click support activity, 63 00:02:33,120 --> 00:02:34,620 and you can see that support activity 64 00:02:34,620 --> 00:02:37,000 extends activity and moving down 65 00:02:37,000 --> 00:02:41,730 click on activity, activity extends ContextThemeWrapper, 66 00:02:41,730 --> 00:02:43,780 keep going, I did say there was a lot of this, 67 00:02:43,780 --> 00:02:46,010 this is one mechanism that Google used 68 00:02:46,010 --> 00:02:48,460 for providing backwards compatibility by the way. 69 00:02:48,460 --> 00:02:49,600 So clicking on, 70 00:02:49,600 --> 00:02:51,873 control or command clicking ContextThemeWrapper, 71 00:02:52,950 --> 00:02:55,390 you can see now that ContextThemeWrapper 72 00:02:55,390 --> 00:02:56,740 extends ContextWrapper 73 00:02:57,870 --> 00:02:59,120 and click onto ContextWrapper, 74 00:02:59,120 --> 00:03:00,510 control or command click, 75 00:03:00,510 --> 00:03:03,570 you can see that ContextWrapper extends Context. 76 00:03:03,570 --> 00:03:06,710 So that means that an instance of AppCompatActivity 77 00:03:06,710 --> 00:03:09,920 can be used where any of those classes are needed, 78 00:03:09,920 --> 00:03:11,780 because of inheritance it contains all 79 00:03:11,780 --> 00:03:14,580 of the methods and properties of all its base classes 80 00:03:14,580 --> 00:03:16,980 and therefore can be classed to any one of them. 81 00:03:18,250 --> 00:03:20,450 Right, so let's close this down. 82 00:03:20,450 --> 00:03:22,770 And noting that in some cases we did get 83 00:03:22,770 --> 00:03:24,980 some of the proper source code working, 84 00:03:24,980 --> 00:03:27,170 but not all of it, so clearly there's a bug there. 85 00:03:27,170 --> 00:03:28,970 Which is the reason why we've got some working 86 00:03:28,970 --> 00:03:31,990 but the other one's we only got the decompiled version. 87 00:03:31,990 --> 00:03:33,430 I'm sure Google will fix that in time. 88 00:03:33,430 --> 00:03:35,180 Anyway, we'll close all those down. 89 00:03:36,220 --> 00:03:39,110 Alright, so I just closed down everything now. 90 00:03:39,110 --> 00:03:41,280 We can open up what we need in the next video. 91 00:03:41,280 --> 00:03:43,050 And speaking of that next video, 92 00:03:43,050 --> 00:03:45,943 we'll see how to remove the up button from the toolbar.