Latest News

How to create a Weather App on Android

Hello peeps,

Time for another Blog Post this year. Well, last month I had attended an "Android Internship" Workshop at our college, which is actually a CS With Android course offered by Google. Since many of my colleagues didn't know Java, we were given a tour of Java programming for the first three days, followed by a session on AI2 App inventor by MIT. Later did we started doing the actual beast : Developing Apps with Android Studio.

First of All, I would Like to thank Chandru etta, for teaching us all the amazing things during these 12 days.

After the workshop ended, we were given the assignment to build an app under an incentive that the best ones would be sent to Google. I finished building one yesterday. It's a weather app called Simple Weather. The app was made by concepts which were not taught to us in the class.

FINDING THE SOURCE CODE

Yeah, folks, my app is completely open source and hosted on GitHub. The source of my app can be found here

HOW I DID IT?

Now, folks, you might have entered an address on your mobile browser, and it loads up the webpage. But here's the thing, there are various steps running within the browser just to display the page, you just don't see that happening (apart from the loading spinner or the progress bar). My app is no different. There are various processes underlying just to display the weather data of the current City.

Implementation

Here's how I made my app working:

  1. Created a URL object, which has the web address to retrieve the input (The city is retrieved from a SharedPreferences File).
  2. Opened connection to the URL Objects, thereby successfully connecting to the internet.
  3. Created a BufferedReader Object, which reads the output we get from the URL (in JSON format)
  4. The output from the URL is converted to a StringBuffer. BufferedReader reads every line of the output and then appends it to the StringBuffer
  5. Then this output is converted to a JSONObject by converting the StringBuffer to a String.
  6. This JSONObject is then returned to my main Fragment (not Activity)
  7. This JSONObject is rendered by the renderWeather method in my main Fragment.
  8. This method does the job of displaying all the data on the main Screen.
  9. The onCreateView() method of this fragment maps the Resources from the Java file (should be a class instead) to the Resources in the Layout.xml file

CODE

So okay, here's my code:

1. WeatherActivity.java

2. WeatherFragment.java
3. CityPreference.java
4. RemoteFetch.java
5. fragment_weather.xml
6. activity_weather.xml

No comments:

Post a Comment

K Anywhere Designed by Templateism.com Copyright © 2014

Theme images by Bim. Powered by Blogger.