1 00:00:00,320 --> 00:00:03,821 All right, so how are we going to get back to the start of our app? 2 00:00:03,821 --> 00:00:06,990 Let's add a new OnClickListener for this play_again_button. 3 00:00:06,990 --> 00:00:09,697 And then we can explore our options. 4 00:00:09,697 --> 00:00:16,920 So choice2Button.setOnClickListener(new OnClickListener), and there we go. 5 00:00:16,920 --> 00:00:18,540 Now, to get back to MainActivity, 6 00:00:18,540 --> 00:00:21,640 we could use a brand new intent, just like we've seen before. 7 00:00:21,640 --> 00:00:23,680 Except this time, it would be going the other way. 8 00:00:23,680 --> 00:00:26,380 We would be starting the MainActivity from our StoryActivity, 9 00:00:26,380 --> 00:00:30,260 and it would technically work, but it would actually be adding a new activity on 10 00:00:30,260 --> 00:00:34,150 something behind the scenes called our navigation stack, or back stack. 11 00:00:34,150 --> 00:00:35,520 More on that in just a moment. 12 00:00:35,520 --> 00:00:38,206 We actually all ready have a relationship with MainActivity here. 13 00:00:38,206 --> 00:00:40,816 We started StoryActivity from MainActivity. 14 00:00:40,816 --> 00:00:43,836 So, that means we can go back to it with a very simple activity method. 15 00:00:43,836 --> 00:00:47,907 We can call finish here, which will finish the current activity and get rid of it, 16 00:00:47,907 --> 00:00:50,208 taking us back to the existing MainActivity, 17 00:00:50,208 --> 00:00:52,636 which might even still be in memory from before. 18 00:00:55,050 --> 00:01:00,037 Okay, so we come in here, add a new name, start the adventure and 19 00:01:00,037 --> 00:01:03,411 navigate all the way to the end of the story. 20 00:01:03,411 --> 00:01:06,350 And if we hit Play Again, it goes back to beginning. 21 00:01:06,350 --> 00:01:06,860 Cool, all right. 22 00:01:06,860 --> 00:01:09,470 So, this works well but I'd like to improve it slightly and 23 00:01:09,470 --> 00:01:12,390 make our app navigation a little more robust. 24 00:01:12,390 --> 00:01:16,711 When a user taps on Play Again, do we want to restart the story with the same name or 25 00:01:16,711 --> 00:01:20,500 do we wanna go all the way to beginning and have the user enter a new name? 26 00:01:20,500 --> 00:01:21,720 We could do both. 27 00:01:21,720 --> 00:01:24,480 Let's change this to have the play again button restart the story with 28 00:01:24,480 --> 00:01:26,260 the same name at page zero. 29 00:01:26,260 --> 00:01:30,150 And then in the next video, we can talk briefly about Android app navigation and 30 00:01:30,150 --> 00:01:33,150 how to get all way back to the MainActivity in a different way. 31 00:01:33,150 --> 00:01:37,430 So, to restart the story, all we need to do is load page zero again. 32 00:01:37,430 --> 00:01:41,352 We can delete this finish line, or comment out if you wanna save it for reference. 33 00:01:41,352 --> 00:01:44,848 And then type loadPage(0). 34 00:01:44,848 --> 00:01:47,562 We could test this, but we're going to have a problem. 35 00:01:47,562 --> 00:01:48,683 Can you guess what it is? 36 00:01:48,683 --> 00:01:49,806 All right, let's take a look. 37 00:01:52,152 --> 00:01:56,053 All right, so we'll do the story, go through to the end, 38 00:01:56,053 --> 00:02:00,443 click on Play Again, and look at that, we have a missing button. 39 00:02:00,443 --> 00:02:02,545 It's still invisible. 40 00:02:02,545 --> 00:02:04,010 Okay, this is an easy fix. 41 00:02:04,010 --> 00:02:07,170 We can just make sure our buttons are visible each time we load them. 42 00:02:07,170 --> 00:02:12,585 So, here in our fancy new loadButtons method, let's add a line at the top. 43 00:02:12,585 --> 00:02:16,540 Choice1Button.setVisibility, and 44 00:02:16,540 --> 00:02:19,880 we'll just set it to View.VISIBLE each time through. 45 00:02:20,980 --> 00:02:28,310 And we can do the same thing for choice2, choice2Button.setVisibility, View.VISIBLE. 46 00:02:28,310 --> 00:02:29,337 Let's just make sure this is working. 47 00:02:32,516 --> 00:02:34,409 Okay, start the adventure. 48 00:02:34,409 --> 00:02:36,612 Go to the end, Play Again. 49 00:02:36,612 --> 00:02:39,190 And now we have two buttons working, very cool.