Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Lists and Adapters (2015) Using Parcelable Data Parceling Data

Kyle Baker
Kyle Baker
8,211 Points

Confused

How much of this should I be getting at this point, and will it all come together at the end of the Tech Degree? I'm constantly failing to understand why certain things are done and there are just so many different tools and methods and libraries.

Ben Deitch
Ben Deitch
Treehouse Teacher

What's gotcha the most confused?

Kyle Baker
Kyle Baker
8,211 Points

The abbreviations that are used sometimes confuse me. MVP, URI, URL, HTTP, MVC, API (in particular) etc. I do know a lot of these now, but when so many are used and expected to be understood, it get's difficult when Ben Jakuben is trying to explain something. Speaking of the explanations, it might just be me, but I understand probably half of what is being said at any given time. There are so many methods that seem to be glossed over and a lot of it feels like monkey see monkey do at this point. I'm confused how you map code to the UI, all these packages and classes make things hard to follow, the requesting info from the internet is probably the most mind boggling out of everything. So far, designing the UI is fine and I seem to be getting that, it's just using Java with it. There's my spiel, do you think I'm not where I'm supposed to be?

Ben Deitch
Ben Deitch
Treehouse Teacher

Na, you're doing fine! It's totally normal to feel absolutely perplexed by a lot of this stuff, and some of it does just take time to 'sink in'. So I wouldn't be to worried if you don't understand everything just yet. That said, is there anything particular about requesting info from the internet that I could help clear up? It's definitely not the easiest thing to get a handle on :)

Kyle Baker
Kyle Baker
8,211 Points

Thanks for the encouragement! I couldn't tell if I was struggling way more than I should be. But yeah, if you could possibly explain how Internet requests work in general, that'd be cool. Based on Stormy, it looks like you need to get a specific URL (is it wrong to say API URL?), put OKHTTP3 in dependencies , create a request, call request and get data with JSON. It's just kind of hard to see how all the code that's used works together.

Ben Deitch
Ben Deitch
Treehouse Teacher

Sure. So let's start with the Stormy API (now named 'Dark Sky'). Dark Sky's done a ton of work compiling and keeping up to date a huge database of weather data, and they let us access that data through their API. The specific API endpoint we use is https://api.forecast.io/forecast/{api key}/{lat},{lng}. Think of it as a black box where we can send coordinates and they'll give us back the weather for those coordinates as a JSON file. Also, they only allow access to folks with valid API keys, this way they can make sure no one is using the service in a way that negatively impacts other users (e.g. pinging it 1000 times a second which would slow down the service for everyone else).

Here's an example using Indianapolis, IN:

  • Using Ben J's API key from the video: 27974c4bc33201748eaf542a6769c3b7
  • Latitude: 39.82
  • Longitude: -86.21

Link -> https://api.forecast.io/forecast/27974c4bc33201748eaf542a6769c3b7/39.82,-86.21

This comes back to us as a JSON file. JavaScript Object Notation, is just that, it's just the way we would write an Object in JavaScript. Here's a simple example of an Object with the 'name' property set to 'Mike' and a 'children' property which contains 3 other Objects named, 'Karlie', 'Marge', and 'Leopold'.

{ 
  "name": "Mike",
  "children":[
    {"name": "Karlie"}, 
    {"name": "Marge"}, 
    {"name:" "Leopold"}
  ]
}

And actually, you can copy the JSON from that link, paste it in here, and then click on the 'Viewer' tab to see exactly what those Objects are.

From the Android side of things, we're using the http library to help us make the call to the API and handle receiving data back. Once we've got the data, we use a different library to help make JSON really easy to work with and then we parse the data and update the UI.

How'd I do?

Kyle Baker
Kyle Baker
8,211 Points

I think you did a good job explaining. If I can sum it up correctly, API key = url. You use this url to link to the API to pull JSON data through requests. You then utilize a library so that the JSON data can easily be used in your application. Also, would I be correct in saying that the data returned is not always in JSON? And can all API keys be altered to retrieve different data? (like in the case of Stormy, the lat and long can be changed in that URL to get the forecast for different locations). Thanks for taking the time to respond by the way :).

Ben Deitch
Ben Deitch
Treehouse Teacher

Close but not quite. The URL is the API endpoint. The API key is a key that you provide to the API endpoint to prove to Dark Sky that you're a valid user. The data should always be JSON because per Dark Sky's docs on what type of response to expect it should be "a UTF-8-encoded, JSON-formatted object". And you can totally do that with different lat/lng coords, give it a shot! In Google Maps, right-click and choose "What's here?" and then it'll show you the lat/lng of where you clicked.

Kyle Baker
Kyle Baker
8,211 Points

Ahhh, my bad. I should've gotten that from the other response that you gave me (the API key bit). And what I meant to say, the data sent isn't always JSON in the case of different websites, right? I get Dark Sky uses it, but would JSON be used if I were trying to pull data from Wiki for example (of course I'm blindly assuming that such a thing could even be done, but it's just an example website). I also did try a lat and long the other day cus Ben mentioned you could mess with location in one of the videos. It seemed to give me the wrong temperature but that's probably because I didn't change the timezone.

Ben Deitch
Ben Deitch
Treehouse Teacher

That's correct. It's up to whoever created the API as to how to return the data; though JSON is almost always one of the options. Other popular choices would be XML, CSV, or just a plain TXT file.

Kyle Baker
Kyle Baker
8,211 Points

Good to know. I'm going to have to pay heed to the documentation for sure in the future. Thanks a ton :)

Michael Nock
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michael Nock
Android Development Techdegree Graduate 16,018 Points

I've been feeling the same way with a lot of things in this course, in particular connecting to the internet. The OkHttp library for example just feels like a lot of magic, how it got moved off the UI thread, etc. If i wanted to use it in another project, i think i'd only be able to copy/paste the code from this course. But i think if you try writing some of your own apps using OkHttp (or some other library) and using this app as a starting point, it'll start to make sense. The next project seems like it's gonna be fairly similar to this as well (the movie night project), so that should help solidify some things. I think you don't really understand what all this does until you really start using it/writing code of your own.

I found a list of APIs here which you could try using to make some sample apps of your own:
https://github.com/toddmotto/public-apis

1 Answer