Creating An Android Weather Forecast Application in The Android Studio
Creating An Android Weather Forecast Application in The Android Studio
Creating An Android Weather Forecast Application in The Android Studio
Abstract: A large number of requests that can be made on a computer can now be realized on
smartphones or tablets. Because of their high hardware performance, mobility and low cost, smart mobile
devices take on the primacy of classical computers in many spheres of life. The smart mobile software
market is rapidly increasing, and the need for experts in this field is enormous. In this paper an analysis
of operating systems of mobile devices was performed, the most commonly used development
environment for application programming, and the process of development of weather forecast
application on the Android platform is shown.
Keywords: Android; Java; smartphones; application
285
Engineering Education and Practice Aleksandrov and Vulović
286
Engineering Education and Practice Aleksandrov and Vulović
"activity_main.xml". The next step in developing important that each component in the xml file has
this application is to create a user interface using its own unique id so the connection would be
the xml file and certain components such as successful. The same principle applies to
"TextView", "ImageView", and components that connecting other components, such as
allow the layout of components on the screen such ImageView. After this step, it is possible to
as "RelativeLayout" and "LinearLayout". These dynamically display text on the screen by simply
components can be added via xml file or via java calling the "setText (String s)" method using the
code in the java class. In this case, the TextView object. The "setImageResource
components are added directly to the xml file. As (Resourse id)" or "setImageBitmap (Bitmap bm)"
the names themselves suggest, "TextView" is can be used to set up images using the
used to display text, and "ImageView" to display ImageView object.
images. Each component serves to display certain In order to display the desired textual and
information on the screen. From the above, it is graphical data on the user interface, it is
necessary to add more "TextView" components necessary to load these data from the service on
that will be used to display the text and also which the user account is created. Information
weather information for the location for which we about current temperature, brief description of
search weather forecasts, the time of the last current weather conditions, pressure, humidity,
update, a brief description of the weather wind speed and direction data are required. To
forecast, the current temperature, as well as the obtain these data, an auxiliary class is created
humidity, pressure, wind speed and UV indexes. under the name "MyWeather". This class will
"ImageView" are used to display graphic elements contain all the information that is needed for
on the interface, such as background images, display on the screen. The object of this class is
graphics that represent the current weather initialized when the application receives a
situation and etc. The size and color of the text as response from server. Before communicating with
well as the size of the images are also defined in the server, it is necessary to determine the
the xml file. After adjusting and positioning the geographical length and width of the place where
components on the screen, we need to connect the user is located. To obtain these data, it is
the elements from the xml file with the java class, necessary to grant the appropriate permissions:
in order to be able to display the data that is "android.permission.ACCESS_FINE_LOCATION"
obtained, and also we need to implement the logic and
for collecting data from the server. It is important "android.permission.ACCESS_COARSE_LOCATION.
to note that each component added to the xml file Also, for the communication with the server, the"
must have its unique "id" so that it can be android.permission.INTERNET" permission is
connected to the java class. Figure 5 shows the required. After the granting this permission, using
created xml file. the "LocationManager" we can detect the current
geographic position of the user. The current
location information is obtained in the pre-defined
method "public void onLocationChanged (Location
location)" that passes the "Location" object. Using
"Location" object, we can get location information
and then the request is sent to the server to get
weather information. The request is sent via the
auxiliary AsyncTaskHelper class that inherits the
AsyncTask class. The reason for using the class
that inherits the AsyncTask class is that in this
way, the request will be sent to the server in a
Figure 5. Creating xml file background thread, so the main thread of the
After creating the interface, it is necessary to application is not affected. This class has its own
connect the xml file with the java class, as well as method "String doInBackground (Void ... voids)"
the components that are used in the xml file. within which the request is defined, and
When creating a new activity, the connection depending on the performance of this method, it
process of java classes and xml files takes place returns the corresponding string as a return
automatically by calling the "setContentView parameter. Sending requests is done by writing
(R.layout.activity_main)" method that is called in the following code:
the "onCreate()" method. The next step is to URL url;
connect a component from an xml file to a java HttpURLConnection urlConnection = null;
class by creating an object of the appropriate type try {
url = new URL(query);
and calling the "findViewById (int id)" method.
urlConnection = (HttpURLConnection)
Connecting a component for displaying text can url.openConnection();
take the following form: TextView txtTemperature
= findViewById (R.id.txtTemperature). It is
287
Engineering Education and Practice Aleksandrov and Vulović
288
Engineering Education and Practice Aleksandrov and Vulović
3. CONCLUSION REFERENCES
The development of a modern information society [1] http://gs.statcounter.com/os-market-
must be based on the application of new ICT share/mobile/worldwide (15.03.2018.)
technologies. The use of smart mobile devices in [2] https://www.tutorialspoint.com/android/andro
all segments of society requires the development id_application_components.htm (16.03.2018.)
of new mobile applications. The global software [3] https://developer.android.com/guide/compon
ents/activities/activity-lifecycle.html
market in this area is growing at a tremendous
(16.03.2018.)
pace, so the need for education of IT specialists is
very high. This trend of the development of
modern technologies enables the rapid
development of the economy in the IT sector. Of
great importance is the advancement of the
educational system, which must be modular and
dynamic, so that it can quickly implement new
technologies into plans and programs in all of the
levels of education.
289