1 00:00:00,580 --> 00:00:03,497 (electronic music) 2 00:00:05,490 --> 00:00:07,270 All right, so we've written the code now 3 00:00:07,270 --> 00:00:10,160 to save the task details, let's see if it works. 4 00:00:10,160 --> 00:00:12,639 We still haven't got the code to display the tasks yet, 5 00:00:12,639 --> 00:00:14,800 but we're studying that in the next video. 6 00:00:14,800 --> 00:00:16,394 But we can check the Logcat to make sure 7 00:00:16,394 --> 00:00:18,078 our data has been saved. 8 00:00:18,078 --> 00:00:20,140 If you wanna check the database, 9 00:00:20,140 --> 00:00:21,630 which I'll be doing in a moment, 10 00:00:21,630 --> 00:00:23,060 make sure you're not using 11 00:00:23,060 --> 00:00:25,040 one of the emulators with Google Play. 12 00:00:25,040 --> 00:00:26,790 They don't provide the permissions we need 13 00:00:26,790 --> 00:00:29,770 in order to open the database on the device. 14 00:00:29,770 --> 00:00:30,603 So what I'm going to do, 15 00:00:30,603 --> 00:00:32,790 because I installed a Google Play version 16 00:00:32,790 --> 00:00:34,546 of the emulator API 28, 17 00:00:34,546 --> 00:00:37,520 I'm going to go ahead and create a new one. 18 00:00:37,520 --> 00:00:38,353 Before I do that, though, 19 00:00:38,353 --> 00:00:40,293 I'm going to edit the one we created. 20 00:00:41,220 --> 00:00:42,910 I'll just change the name just to make it clear that 21 00:00:42,910 --> 00:00:45,433 this is the Play version, Google Play version. 22 00:00:47,520 --> 00:00:49,660 And I'm gonna create a new virtual device, 23 00:00:49,660 --> 00:00:50,993 Nexus 5X again. 24 00:00:52,610 --> 00:00:54,310 This time, we don't want the Google Play version. 25 00:00:54,310 --> 00:00:56,350 I just gonna click x86 Images, 26 00:00:56,350 --> 00:00:58,680 I'm gonna go for the Google API version, 27 00:00:58,680 --> 00:00:59,987 or, of course, we can access the database, 28 00:00:59,987 --> 00:01:03,200 and I'm gonna use API Level 28 again. 29 00:01:03,200 --> 00:01:06,182 I'm gonna call this one API, just so it's clear to me 30 00:01:06,182 --> 00:01:09,722 that we're using the Google API version. 31 00:01:09,722 --> 00:01:11,312 All right, so now that we've got that created, 32 00:01:11,312 --> 00:01:15,168 I'm going to just start it. 33 00:01:15,168 --> 00:01:19,168 And I'll close down this Virtual Devices dialogue. 34 00:01:22,410 --> 00:01:24,060 Now obviously, because this is a brand new emulator, 35 00:01:24,060 --> 00:01:26,030 I won't open in the apps installed. 36 00:01:26,030 --> 00:01:29,070 So if you've already created an emulator, 37 00:01:29,070 --> 00:01:31,652 your probably want to uninstall the app from your emulator 38 00:01:31,652 --> 00:01:34,210 to make sure there's no existing data in there, 39 00:01:34,210 --> 00:01:36,040 because we're gonna run this version of the app 40 00:01:36,040 --> 00:01:38,600 and enter some data as we go through. 41 00:01:38,600 --> 00:01:40,093 But again, I just created an emulator, 42 00:01:40,093 --> 00:01:41,430 so I won't need to test for that. 43 00:01:41,430 --> 00:01:43,193 So I'm gonna make this a bit bigger. 44 00:01:46,470 --> 00:01:48,057 This over to the right. 45 00:01:48,057 --> 00:01:49,403 I'm gonna run this, 46 00:01:54,260 --> 00:01:55,410 just by pressing Start. 47 00:01:56,400 --> 00:01:58,680 All right, so I don't need to uninstall 48 00:01:58,680 --> 00:01:59,700 the app from my emulator 49 00:01:59,700 --> 00:02:01,157 to make sure there's no existing data, 50 00:02:01,157 --> 00:02:02,580 and that's because you just saw me 51 00:02:02,580 --> 00:02:04,237 create a new emulator. 52 00:02:04,237 --> 00:02:06,720 If you're running an existing emulator, 53 00:02:06,720 --> 00:02:09,919 then uninstall the app to remove all the data. 54 00:02:09,919 --> 00:02:11,600 And in turn, what I'm going to be using here 55 00:02:11,600 --> 00:02:14,300 for adding new data, which we want to test, 56 00:02:14,300 --> 00:02:16,540 I'm gonna be really boring in my choice of tasks names, 57 00:02:16,540 --> 00:02:18,150 but there's a good reason for it. 58 00:02:18,150 --> 00:02:19,070 We'll see that is 59 00:02:19,070 --> 00:02:20,850 when we come to respond to tabs 60 00:02:20,850 --> 00:02:22,470 on the items a bit later. 61 00:02:22,470 --> 00:02:23,690 For now, though, once the app's running, 62 00:02:23,690 --> 00:02:25,520 make sure that Logcat's visible. 63 00:02:25,520 --> 00:02:27,570 So I'm gonna go back and click on Logcat. 64 00:02:28,430 --> 00:02:30,030 And notice that I'm still in floating mode 65 00:02:30,030 --> 00:02:31,030 from the previous video, 66 00:02:31,030 --> 00:02:32,800 so I'll leave that in that mode. 67 00:02:32,800 --> 00:02:33,680 I have noticed, though, 68 00:02:33,680 --> 00:02:35,920 that Logcat now behaves a bit differently 69 00:02:35,920 --> 00:02:37,568 with this release of Android Studio. 70 00:02:37,568 --> 00:02:40,590 Over in the filter box over here to the right, 71 00:02:40,590 --> 00:02:42,654 it often resets to No Filters. 72 00:02:42,654 --> 00:02:44,090 If I click this now, 73 00:02:44,090 --> 00:02:46,230 the option to show any selected application, 74 00:02:46,230 --> 00:02:47,549 which is the one we want here, 75 00:02:47,549 --> 00:02:49,147 is also unavailable sometimes, 76 00:02:49,147 --> 00:02:51,760 and you can see, at the moment, it's not showing. 77 00:02:51,760 --> 00:02:54,200 It seems to be a bug, and if that happens, 78 00:02:54,200 --> 00:02:56,810 use the second drop-down from left over here 79 00:02:56,810 --> 00:02:58,045 to choose your application again, 80 00:02:58,045 --> 00:02:59,360 and I think that it is actually chosen, 81 00:02:59,360 --> 00:03:00,610 but I'll click on that again anyway. 82 00:03:00,610 --> 00:03:03,090 And if I come back over here, 83 00:03:03,090 --> 00:03:05,479 the option to show any selected application, 84 00:03:05,479 --> 00:03:07,890 which is the one we want, is now there. 85 00:03:07,890 --> 00:03:10,678 I can click on that, and we get to suggest our code. 86 00:03:10,678 --> 00:03:13,479 And once, I'm gonna take the opportunity to remove 87 00:03:13,479 --> 00:03:16,973 what we put in there before to the filter. 88 00:03:17,910 --> 00:03:19,610 So we see everything for this app. 89 00:03:20,520 --> 00:03:24,160 All right, so loading up our emulator again, 90 00:03:24,160 --> 00:03:26,930 released, bring it back on screen. 91 00:03:26,930 --> 00:03:29,430 Let's get started, so I'm gonna click on the plus, 92 00:03:30,660 --> 00:03:33,247 the screen to add data screen appears, no surprises here, 93 00:03:33,247 --> 00:03:36,290 and we call all the tasks Task with a number, 94 00:03:36,290 --> 00:03:37,350 starting with the Task1. 95 00:03:37,350 --> 00:03:39,820 Doesn't really matter what we use for the description, 96 00:03:39,820 --> 00:03:42,230 so I'm just gonna enter first task, second task, and so on. 97 00:03:42,230 --> 00:03:44,907 And next, what I'll do, also is, before I do that, 98 00:03:44,907 --> 00:03:47,750 I'm gonna go back into Logcat, 99 00:03:47,750 --> 00:03:49,500 and I'll just put Saving as a comment, 100 00:03:49,500 --> 00:03:51,740 so we know where the log started. 101 00:03:51,740 --> 00:03:52,670 All right, so let's start. 102 00:03:52,670 --> 00:03:53,927 The first one, Task1. 103 00:03:55,375 --> 00:03:57,530 Task description is gonna be first task, 104 00:03:58,790 --> 00:04:01,300 and I'll leave the order or blank for that one. 105 00:04:01,300 --> 00:04:02,950 Click on Save. 106 00:04:02,950 --> 00:04:04,160 All right, and when I clicked Save, 107 00:04:04,160 --> 00:04:05,960 you saw that the events were being logged. 108 00:04:05,960 --> 00:04:07,990 And I go back over and have a look at that. 109 00:04:07,990 --> 00:04:08,880 This is the first time 110 00:04:08,880 --> 00:04:10,530 that we've accessed the content provider 111 00:04:10,530 --> 00:04:11,810 after installing the app, 112 00:04:11,810 --> 00:04:14,348 and we can see the table creation being logged there. 113 00:04:14,348 --> 00:04:17,410 So that's followed by the insert method exiting 114 00:04:17,410 --> 00:04:18,980 with the URI that it returns, 115 00:04:18,980 --> 00:04:20,437 you can see that up there, you can just scroll over, 116 00:04:20,437 --> 00:04:22,463 and we can see it's task slash one. 117 00:04:23,720 --> 00:04:25,855 The URL contains an ID, so that's a good sign. 118 00:04:25,855 --> 00:04:27,710 We wouldn't have an ID 119 00:04:27,710 --> 00:04:30,428 if SQLite hadn't added the record to the database. 120 00:04:30,428 --> 00:04:32,723 So let's go ahead and add another task now. 121 00:04:34,887 --> 00:04:38,027 I'll call this one, not surprisingly, Task2, 122 00:04:38,870 --> 00:04:41,464 second task for the description. 123 00:04:41,464 --> 00:04:44,640 The sort order, this time, we'll add a sort order five, 124 00:04:44,640 --> 00:04:45,473 and save. 125 00:04:46,760 --> 00:04:48,318 If I scroll down, we can see that 126 00:04:48,318 --> 00:04:51,830 we're still getting things updated, and we're confirming 127 00:04:51,830 --> 00:04:53,640 that the data's been saved, that's good, 128 00:04:53,640 --> 00:04:55,700 and we can just scroll over and see 129 00:04:55,700 --> 00:04:57,230 we've got tasks, too, they're showing, 130 00:04:57,230 --> 00:04:58,670 so that's a good sign so far. 131 00:04:58,670 --> 00:05:00,083 Now, back to our app again. 132 00:05:00,083 --> 00:05:03,327 There's another entry, this time, Task3, 133 00:05:05,000 --> 00:05:07,103 description's gonna be third task, 134 00:05:08,750 --> 00:05:10,581 and I'm going to enter the largest possible number 135 00:05:10,581 --> 00:05:13,218 for the sort order, so that's nine nines. 136 00:05:13,218 --> 00:05:14,520 One, two, three, four, five, 137 00:05:14,520 --> 00:05:16,010 six, seven, eight, nine. 138 00:05:16,010 --> 00:05:17,552 It won't let me top any more than that now, 139 00:05:17,552 --> 00:05:20,010 actually, if I try anyway. 140 00:05:20,010 --> 00:05:21,780 So that's also working fine. 141 00:05:21,780 --> 00:05:25,280 I'll save that into the fourth task, 142 00:05:25,280 --> 00:05:28,853 Task4, fourth task, 143 00:05:30,145 --> 00:05:32,820 and I'll leave all the remaining sort orders blank. 144 00:05:32,820 --> 00:05:35,743 So I'm gonna save that, back again to Task5, 145 00:05:37,930 --> 00:05:42,490 fifth task, sort order blank as I mentioned, 146 00:05:42,490 --> 00:05:43,390 and click on Save. 147 00:05:44,450 --> 00:05:45,840 All right, that's enough records. 148 00:05:45,840 --> 00:05:47,000 And we don't have to just trust 149 00:05:47,000 --> 00:05:48,270 the Logcat entries here, by the way. 150 00:05:48,270 --> 00:05:50,672 We can check the records using SQLite 3. 151 00:05:50,672 --> 00:05:53,520 So to do that, we go back to, 152 00:05:53,520 --> 00:05:54,353 actually, what I'll do is 153 00:05:54,353 --> 00:05:56,400 I'll close down the Logcat for now. 154 00:05:56,400 --> 00:05:57,983 Go back to open the Terminal. 155 00:06:00,210 --> 00:06:02,720 I'm going to type adb devices. 156 00:06:05,069 --> 00:06:07,610 I'm gonna type adb space dash s 157 00:06:07,610 --> 00:06:11,320 space emulator dash whatever the number is, 158 00:06:11,320 --> 00:06:13,793 in my case, 5554, shell. 159 00:06:15,360 --> 00:06:17,593 Type su to switch into superuser mode. 160 00:06:18,470 --> 00:06:20,430 And it's at this point that you might struggle 161 00:06:20,430 --> 00:06:22,487 if you're using a real phone instead of an emulator. 162 00:06:22,487 --> 00:06:23,620 And if that's the case, 163 00:06:23,620 --> 00:06:24,910 you can't really check your database, 164 00:06:24,910 --> 00:06:26,600 as you just have to trust the Logcat 165 00:06:26,600 --> 00:06:28,320 until we display the records in the app 166 00:06:28,320 --> 00:06:30,334 a little bit later, whereas our database 167 00:06:30,334 --> 00:06:33,160 in the slash data slash data directory, 168 00:06:33,160 --> 00:06:35,422 in a subdirectory that's the same name as our package. 169 00:06:35,422 --> 00:06:38,850 So in my case, I can check with cd slash data 170 00:06:38,850 --> 00:06:42,680 slash data slash, I can type in learn, 171 00:06:42,680 --> 00:06:45,280 press Tab, that gives me the rest of the package name, 172 00:06:45,280 --> 00:06:46,790 and then, I go into a subfolder 173 00:06:46,790 --> 00:06:49,810 called databases, and press Enter. 174 00:06:49,810 --> 00:06:54,344 And I can type sqlite3 TaskTimer, 175 00:06:54,344 --> 00:06:58,433 capital T for Task, capital T for Timer, dot db. 176 00:06:59,460 --> 00:07:03,413 And we'll select star from tasks. 177 00:07:04,860 --> 00:07:06,440 And you can see that we've got our records showing. 178 00:07:06,440 --> 00:07:09,160 So our code is adding your records 179 00:07:09,160 --> 00:07:11,510 to the SQLite database, which is fantastic. 180 00:07:11,510 --> 00:07:12,800 All right, so before I stop the video, 181 00:07:12,800 --> 00:07:13,970 I'll close down the terminal 182 00:07:13,970 --> 00:07:16,670 by typing exit to leave the SQLite show, 183 00:07:16,670 --> 00:07:18,650 exit to quit superuser mode, 184 00:07:18,650 --> 00:07:21,697 and exit once more to exit from id, 185 00:07:21,697 --> 00:07:24,600 and exit to close down terminal. 186 00:07:24,600 --> 00:07:26,090 All right, so in the next video, 187 00:07:26,090 --> 00:07:28,260 we'll look at creating the adaptor what we'll need 188 00:07:28,260 --> 00:07:29,537 to populate the recycler view 189 00:07:29,537 --> 00:07:32,910 with the task records that we've saved. 190 00:07:32,910 --> 00:07:34,210 See you in the next video.