Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Getting the Dynamic Data4:56 with Ken Alger
We need to update the app to use the data from the Dark Sky API in the HourlyForecastActivity.
Our app is working with our manual, static data. 0:00 Let's make the necessary changes to get our JSON data coming through. 0:03 We'll be touching a lot of different files in this video but 0:07 nothing too extensive in each one. 0:10 In fact, the biggest change in terms of number of lines of code 0:13 we can do right now. 0:17 We can delete our entire getHourData method and HourlyForecastActivity. 0:19 Come down here. 0:25 Can delete that, bye-bye. 0:28 You were great and very helpful. 0:31 Our first step in getting our JSON data is to make the hour class implement the Java 0:34 serializable interface. 0:39 Making an object serializable allows for the object to be safe for later. 0:41 I've put some links for more information about the serializable interface and 0:46 Java serialization in general in the teacher's notes. 0:51 So in the Hour class, Come up here and 0:54 type implements, _Serializable. 1:02 Next, in MainActivity, gonna open that up, we go down to the hourlyOnClick method. 1:11 Down here at the bottom, we need to add an extra to our intent. 1:23 We need a list of hours. 1:25 We can get that from the get HourlyForcastActivity method we wrote over 1:27 in Forecast. 1:30 So we're gonna do a List<hour>, 1:35 quick fix for our imports. 1:40 Call it hours, Arrays.asList(forecast.getHourlyForecast. 1:44 And then we put that information into our intent. 1:54 So intent.putExtra, We'll call it HourlyList. 2:01 And we want a Serializable of hours. 2:14 Now we can turn our attention back to HourlyForecastActivity and get and 2:20 pass in our data. 2:24 Go back to HourlyForecastActivity. 2:25 Here inside onCreate, 2:29 we need to get the data from the intent that we added over in the MainActivity. 2:30 So Intent, Quick fix our imports, call it intent. 2:40 Get the intent, List of hours, we call it hoursList, 2:49 Dual cast, And get our data. 3:00 Get the serializeable data. 3:10 Get SerializeableExtra. 3:14 We called it HourlyList. 3:16 And let's drop this down under new line. 3:25 Here, where we've defined our adapter, and 3:27 we're calling our deleted get our data method. 3:30 We can now replace that with our hoursList. 3:33 That was a lot of steps. 3:39 Let's walk through all that again. 3:40 We updated the hour class to implement Serializable, allowing for 3:43 the data to be saved in memory and passed to the HourlyForecastActivity. 3:47 Next, we headed over to MainActivity. 3:51 Here, we added our hourly data to our intent, with the putExtra method, 3:53 which allows our HourlyForecastActivity to gain access to that. 3:58 Then we headed to HourlyForecastActivity. 4:03 Over here inside onCreate, we were able to get the serialized data 4:06 from the intent with the getSeralizableExtra method. 4:11 Finally, we updated the adapter to use our dynamic data source. 4:15 All right, let's run our app again and see it all working. 4:19 So there is our app we click on hourly forecast. 4:28 There's our data in a recycler view and scrolling around. 4:34 Awesome, well done, we've taken our stormy app and 4:39 added the ability to see hourly data in our recycler view. 4:42 You should be super proud of the work you've put in so far. 4:47 There's one other quick thing we should do in our app to make it work 4:50 a little better. 4:53 Let's take a look in the next video. 4:54
You need to sign up for Treehouse in order to download course files.Sign up