sit207 android programming
TRANSCRIPT
SIT207 ANDROID
PROGRAMMING Duke Amarasena 215200017
PORTFOLIO DESCRIPTION This portfolio demonstrates evidence of Android
application programming. It presents the learning of
unit, particularly describing and reflecting on each of
the topics they were required to learn during the
unit, as well as their answers to weekly practical
exercises given throughout the unit.
This also consists of a weekly summary of each
week’s topic, analysing and discussing how the topic
relates to developing mobile application. It also
contains screenshots and images as evidence of
what is learnt and the things achieved during each
week that contains the layouts, design, codes etc.,
involved within the development of android
application
SIT207 ANDROID PROGRAMMING PORTFOLIO 1
Week 1 Summary
Recap
This is the beginning of the trimester and the start of SIT207 Android Programming unit, where we
started of the basic history, overview and evolution of android in general. The main focus for this
week was the history in general, but we were also to understand the concept of developing UIs and
creating simple applications. We were to also understand the Java language which is mostly used
within android platforms as well as the architecture of android platforms.
For this week purpose, the main target was familiarising and getting know android studio, which will
be the software that we would be using to create and demonstrate the understanding of specific
content that will produced during each practical activity.
Things Learnt
Android is implemented in the form of a software stack architecture consisting of a Linux kernel, a
runtime environment and corresponding libraries, an application framework and a set of
applications. Applications are mainly written in Java and run within individual instances of Dalvik
virtual machines
JavaScript program is an example of cross platform software. Since as long as the browser you are
using knows how to interpret JavaScript codes, the program will run regardless of the platform. Java
is also considered a cross platform to an extent. Java runs on something called the JVM (Java Virtual
Machine). JVM is software installed on a computer that executes programs like a physical machine
with a reserved memory, such as CPU, as Java combines both the approaches of compilation and
interpretation.
SIT207 ANDROID PROGRAMMING PORTFOLIO 2
Prior to what I have learnt from the lecture, the information provided within the android developer
site helps understand the future of the android development and improvement that have been
planned for development of android, things such as design structure a and development stages of
android are understood to be simple, fast and improved for efficiency. With design, there are layout,
styles, animations, usability etc., are just some of things that are considered to improve android
development.
With information provided on the developer site, I have learnt important principles in helping design
an elegant UI
➢ Design
o Layout: Material design layouts encourage consistency across platforms, environments
and screen sizes by using uniform elements and spacing
o Usage: Involves of predictability, consistency and responsiveness
o Structure: Involves of visually balanced design layouts, where the most measurement
align to an 8dp grid applied, which align both spacing and overall layout.
o Pixel density: screen pixel density and resolution vary depending on the platform,
where device independent pixels and scalable pixels are units that provide a flexible
way to accommodate a design across platforms
➢ Usability
o Accessible design allows user of all abilities to navigate, understand and user the UI
successfully
o Improvement to product accessibility enhance the usability for all users, such as users
with low vision, blindness, hearing impairments and other disabilities.
o Keep it clear, robust and specific, which helps users navigate the app easier, can
accommodate a variety of users and support assertive technologies specific to your
platform
GitHub and VCS (Version Control System) are similar, where GitHub is basically a website and
service that offers web-based hosting service for version control using Git. It offers all of the
distributed version control and source code management functionality of Git and well as adding its
own features. For example, where developers create an app, they make constant changes to the
code, releasing new version up to date and after the first official (non-beta) release.
VCS basically keep these revision straight, storing modification in a central source, which
allows developers to easily work together as they are able to download a new version of the
software, making changes or uploading the new revision.
Practical Exercises
The focus of this week is to learn how to create an android project and some fundamental tools, as
well as focusing on the learning objectives
- Get exposed to the Android developer site (explore it intensively in the future by yourself.
There are a lot of funny stuff there)
- Create an Android project using Android Studio
- Learn to configure ADT, including Android SDK manager, Android Virtual Device (AVD)
manager, use the emulator to emulate the android project.
- Learn to create a project in Android Studio
SIT207 ANDROID PROGRAMMING PORTFOLIO 3
First task was to build our first android app, Hello World
1. Open Android Studio
2. 2. In the pop-up window, select “I do not have a previous version of Android Studio or I do not want to import my settings”, and click OK
3. Wait for it to load
4. After it loads, this windows is popped up, but cancel option it to be selected
5. Select “Do not re-run the setup wizard”, and select OK. This will skip the update process in the future
6. After this, android is loaded and is ready, when the window pops up, we select “start a new
android project”
7. Type an application name to identify the project, such HelloWorld and click next
8. Fill the form, where you select the intended android platform or target
SIT207 ANDROID PROGRAMMING PORTFOLIO 4
9. In the activity template, we choose blank activity (I however clicked empty activity, which is
the same)
10. Then configure activity by typing a suitable activity name and click finish
I managed to get the phone layout and he screen layout displayed per to the instructions provided
SIT207 ANDROID PROGRAMMING PORTFOLIO 5
The screen below shows the result that were gained from following the right approach, however I
encountered minor errors through this process as I was not able to display the text within phone
layout as a result it did not show up, but with consultation with my tutor, unit chair and my peers, I
was able to fix this issue as the results are presented below.
Then I created a virtual machine through which is required to run the app on an emulator, this is
called AVD (Android Virtual Device), which we must create in order to select the device of our
choice and configure to different specifications, this also helps run the created app.
SIT207 ANDROID PROGRAMMING PORTFOLIO 6
Virtual devices is created and shows the detailed description of the created device.
After virtual device was created, it was then time to run the app, giving the issue I had, although it
was not perfect or the right result, I managed to get the app running.
SIT207 ANDROID PROGRAMMING PORTFOLIO 7
Week 2 Summary
Recap
The focus of this week was the android studio environment and configuration, file structure of an
android project and android XML layout. Apart from these main topic we covered and learned some
element in regards to APKs and SDKs tools in which are both considered to be essential part of an
android app. This week we touched on the environment of Android Studio, on the locations of
certain options and tools are placed in the software.
The configuration of android studio is vital as it demonstrate and display the each project according
to the specific configuration, such as importance on file structure and how these displayed within
the application resources. Significance of naming attributes proves vital as each name must match
the other elements.
Things Learnt
Generally a manifest file in computing is a file containing metadata
for a group of accompanying files that are part of a set or coherent
unit. Every application must have an AndroidManifest.xml file in
its root directory. This file manages icons, labels, permissions,
libraries, intent filters and many other configuration parameters related to application. The manifest
presents essential information about the application to the Android system, information the system
must have and need before it can run any of the application's code.
The structure is also consists and precise as it vital to predefine names of folders and insert different
types of resources in their corresponding folders. Android users the folder name to locate resource
files as these folders are used managing the structure of a particular project, folders also help
organise the each file with groups and configures them accordingly to their structure.
In an android project, there are resources that help configure a
project, which are manifests, java and res. Resources are basically
anything that is not code, which include XML layout files, language
packs, images, audio/video files etc., these recourses are defined
in the res folder of the project. The res file structure,
• Contain all application resources
• Include directories
o Drawable: for images, such as BMP, JPG etc.
o Layout: XML files complied into screen objects
o Menu: XML files defining application menus
o Values: XML files containing string values
o Mipmap: place to put the launcher icons
There are issue with running android applications which number 1 issue being heterogeneous
devices, where an android application might run on heterogeneous device with different
characteristics, such as screen size, language support, keyboard type, input devices etc.
This the biggest issue so far, however there are solutions to this cause, which are,
SIT207 ANDROID PROGRAMMING PORTFOLIO 8
• Traditional Solution:
o Foresee all the alternative in Java code
o The code is full of if-else cases
o Recompile when need to change layout or add a new language package
• Android Solution:
o Separate code from application resources
o Use declative XML-based approach to define resources (image, files, layout, text
etc.)
The two type of group is android, which are View and ViewGroup, view is the base class for widgets
which are used to create interactive UI components, ViewGroup subclass is the base class for layout,
which are invisible containers that hold other views or other ViewGroups.
View objects are used specifically for drawing content onto the screen of an Android device.
While you can instantiate a view in your Java code, the easiest way to use them is through an XML
layout file. An example of this can be seen when you create a simple "HelloWorld" application in
Android Studio.
The layout file is the one named activity_main.xml, looking something like this.
A ViewGroup is an invisible object used to contain other View and ViewGroup objects in order to
organize and control the layout of a screen. ViewGroup objects are used for creating a hierarchy
of View objects (see below) so that you can create more complex layouts. That said, the more simple
you can keep a layout, the more performant it is.
Android consists of variety of layouts which helps structure the project and configuration better,
which are,
• Linear Layout: This is a ViewGroup that will lay child View elements vertically or horizontally.
Layout and the result of which
the information or content will
be presented in the final result.
This is also the comparison
between the two different
types of orientation and how
the difference of information
will be presented.
SIT207 ANDROID PROGRAMMING PORTFOLIO 9
• Table Layout: This ViewGroup will lay child View elements into rows and columns, controlled by attributes
• Relative Layout: This allows you to layout child elements in positions relative to the parent
or siblings elements.
• Frame Layout: This layout arranges child View
elements relative to top left point. Views that you
add to a Frame Layout are always anchored to the
top left of the layout.
SIT207 ANDROID PROGRAMMING PORTFOLIO 10
Practical Activities
Objectives for this week are,
• Leaning to use Balsamiq, which wire framing tool for mobile app development
• Designing android app UI
• Exploring file structures of android project
The focus was developing an UI for FishTrap app using Balsamiq, which the UI should look something
similar to this (shown below),
The tutorial provided demonstrate the use of software and creating the UIs, this particular software
has availability of different options and icons that can be used develop different types of UIs. I
personally have used similar software to design UIs as the tutorial provided with detailed
information on mastering the software. The screen below my understanding of Balsamiq and how
managed to developed the UI.
Registration page for
new customers
The login page, existing
customers
SIT207 ANDROID PROGRAMMING PORTFOLIO 11
Week 3 Summary
Recap
This is week involves of understanding some significant principles that are vital in android
programming. Classes, objects, package, inheritance, interfaces and nested classes demonstrates the
development of an android app. These prove very important as it is essential to understand theory
of these concepts which will help better understand development protocols and programming in the
app development.
The concepts defined above will demonstrate the use of software and the ways to apply those in
building an app, but we also covered the language as this crucial in terms of adding functionality to
an app. The language and these concept help design and implement android application for mobile
devices, as we will look further details into the development stage of mobile apps.
Things Learnt
Classes and Objects:
• An object is a thing that we teach the computer to do something, so that the computer
knows exactly what it requires. For example, bicycle as we first define the object and its
properties as we also define its attributes and the method in which to implement it into
action. Attributes of a bicycle could gear or speed and the method should be what these
attributes should do when it’s implemented. The bicycle example can be implemented by
producing the following code:
• A class can be considered as a template, a prototype or a blueprint of an object, which
basically is a method for a particular object. It should define the characteristics of the object
and can define specific action the object should and can do and is the fundamental structure
in object-oriented programming.
SIT207 ANDROID PROGRAMMING PORTFOLIO 12
• A special method which can detect an object, it has the same name as the class is called a
constructor. When you use the new keyword, which initiates the newly created object, an
example would be MyClass myClassObj = new MyClass();, as this example results in a
new MyClass object being created. The bicycle example can be demonstrated with these the
constructor, which is shown below,
Naming conventions:
• Class names: Must be represented in the mixed case starting with upper case
• Variable or Object Names: These are in mixed cased staring with lower case, such as bicycle
or circle.
• Method Names: Represented in verbs and written in mixed case starting with lower case,
such as getName(), computeTotalWidth().
Package:
• Packages can contain more than one class definition
• These are often contain libraries an can be defines in hierarchies
• This is a namespace that organise a set of related classes and interfaces.
• Keep set of data in organised manner in package can be similar to folder that are presented
in a computer.
Inheritance:
• This is basically the process of when one class obtain the properties of another, such as
method, fields or attributes
SIT207 ANDROID PROGRAMMING PORTFOLIO 13
• The use of inheritance helps with the information being more manageable in categorised
order.
• With inheritance we are able to extend the code that is already written in the manageable
manner.
• A class that inherits the properties of other is known as a subclass and the class whose
properties are inherited is known as superclass (base class, parent class).
• We declare subclass as class B extends A { . . . }, meaning B is a specialisation of class A, a B
object is an A object and class B inherits the attributes and methods in class A.
• Example shown below shows classes inherit the attributes of all ancestor classes
Modifier:
• Basically a special language keyword that modify the behaviour of a class, method or a
variable
• There are three common modified used in programming language, which are public, private
and protected, however we use only three modifiers that appear at the beginning of a class,
which are abstract, public and final.
• Defining a class with these modifiers as each are different,
o Public: makes the class visible to classes that not in the same page
o Abstract: specifies that the class cannot be instantiated
o Final: identifies that the class cannot be extended
• All modifiers are essentially optional, however it is suggested to add them as they will best
describe the intended whatever is being declared.
• Generally access modifiers defines the program, public is the rule for methods you want
others to use. Private is the default for class-level variables and for variables you don't want
subclasses to directly access. Protected is typically used within related classes to allow
internal access to data but kept away from outside users.
SIT207 ANDROID PROGRAMMING PORTFOLIO 14
Abstract Classes:
• These classes basically classes that contain one or more method
• An abstract method is a method that is declared, but contains no implementation.
• Abstract classes may not be instantiated, and require subclasses to provide implementations
for the abstract methods.
• A method that has been declared but not defined is an abstract method
Examples of an abstract class, as this example is an method of making animal noises
Public abstract Animal
{
Pubic void eat (Food food)
{
// do something with food….
}
Public void sleep (int hours)
{
Try
{
// 1000 millisecond * 60 secs * 60 mins * hours
Thread.sleep (1000 * 60 * 60 * hours);
}
catch (InterruptedException ie) {/* ignore */}
}
Public abstract void makeNoise();
}
• You cannot instantiate (create new object) an abstract class as he computer does not know
how to deal with the methods with unknown behaviours.
• Abstract classes can be subclassed, an abstract method only has signatures.
• These classes are beneficial in defining a general category containing specific concrete
classes
Interface Class:
• An interface class in java is a reference, which it is similar to a class as it is collection of
abstract methods
• With the abstract methods, an interface may also contain constants, default method static
method and nested types
• This can contain any number of method
SIT207 ANDROID PROGRAMMING PORTFOLIO 15
• This can declare methods but does not necessarily supply bodies for them.
interface KeyListener {
public void keyPressed(KeyEvent e);
public void keyReleased(KeyEvent e);
public void keyTyped(KeyEvent e);
}
• Written in a file with .java extension and byte code of an interface appears in a .class file
• Interfaces appear in packages, however it is important to known that interfaces are different
from a class
• You cannot instantiate an interface and all the methods are implicitly public and abstract.
• In android you may extend a class, but you implement an interface, such as class
MyListerner implements KeyListerner, ActionListenner{- - -}
• When saying a class implements an interface you are promising to define all the methods
that were declared in the interface
• We use interface because a class can only extend on other class, but it can implement
multiple interfaces, also you can write method that work for more than one kind of class.
Anonymous Classes:
• These classes are used if an object to be create, but there is no need to name that object’s
class
• The class definition is embedded inside the expression with the new operator.
• An anonymous inner class can be useful when making an instance of an object with certain “extras”, such as overloading methods of a class or interface, without having to actually subclass a class.
SIT207 ANDROID PROGRAMMING PORTFOLIO 16
• Anonymous inner classes are useful in writing implementation classes for listener interfaces in graphics programming and interpretation.
• Anonymous inner classes are
mainly created in two way, class
(abstract or concrete) or
interface
Java Comments:
• Comment within a code or documentation is important and essential as it produce the
programmer
• There are three types of commenting in java,
o Single Line: commented within a single line, such as // this is a C++
o Multi Line: couple of lines are used to comment the lines of code, such /* this is Java
example */
o Documentation comment: these are mostly written in a few lines or a small
paragraph, such as /** this is an example of special java doc……… */
Practical Activities
This week was the focus of creating out first UI (User Interface), the interface can be created
however we like as we are also to follow an instructive video on creating an UI, but had a choice as
we did not necessarily have to follow the video and it was presented as a guide.
The code below provides the basic email login screen with a email address input section and a login
button.
SIT207 ANDROID PROGRAMMING PORTFOLIO 17
The screen below show the result when ran through the emulator, however the login button has no
functionality as this is just design process.
The code below add more functionality to the previous as it adds the two page view links, as the
layout changes are also applied to the basic view of the page.
Ideally a valid email address is to be
entered when login in, however the
validation functionality is focus in this
activity.
SIT207 ANDROID PROGRAMMING PORTFOLIO 18
This is basically the result which the above code produces as there are changes significant
The result of the code here produce the
page with email option with a login option
of which can be accessed with a valid
email, although that functionality has not
been added to this particular code.
The code is demonstration of the
previous layouts being altered to make a
new page with the addition of more
interactive elements, result of this is as
show
SIT207 ANDROID PROGRAMMING PORTFOLIO 19
This is a demonstration of the similar idea of a login options but with the addition of more options
with adds functionality.
The result of which produce the above outputs
although this is not completed layout as it
should also consist of gender prompt and with a
female option as well, but this is the general
idea of the task
SIT207 ANDROID PROGRAMMING PORTFOLIO 20
Week 4 Summary
Recap
This week’s focus on the UI development and the uses of the basic UI widgets, on how to
implement them on our design. This was main focus due to fact that UI development is involved in
our project development. The uses of the basic input controls such as text fields, text view, buttons,
checkbox, radio buttons etc., were the focus as it is heavily involved in the process of the design
process. I personally learned a lot of about the hotkeys and how it plays an essential part in the
design process and how it is helpful.
We also discussed on the functionality side which is essential in the developing an app and
the implementation process of adding the functionality with adding xml codes to the design process.
Finally the importance of the manifest.xml file was addressed and discussed as this file present
essential information about the application.
Things Learned
The basic input controls basically define or displays how the UI design will be presented to user and
each of these inputs have different purposes and a variety in the implementation process.
TextView & TextFields:
• TextView is used to display text on screen and does not allow editing in itself
• TextField will allow to users to type text, which can vary from a plain text, a person name, a
password etc.
• This can be editing via variety of properties, such as height or width
• Can be used to display text as a prompt, such as an user name
This is the view,
where information is
shown in a TextView
TextField properties are
here as they come in a
variety of attributes,
which can be used for
designing an interface
SIT207 ANDROID PROGRAMMING PORTFOLIO 21
Buttons:
• These allow users to have action in an app, which adds functionality and action to a
particular element
• They vary in different attributes each with different types, such as normal, image, toggle and
radio buttons
• Each of these types of buttons rely on different xml classes as they can used to present the
buttons with more consistency
Image View:
• This view will display image views that have been placed in the
layout
• The displayed view would be like an artifect which can be
adjusted in XML file
• This view displays any image as it can be an image or an icon
based image, which is edited through code
• Scaling, resizing and placement of the image can be edited
through its attributes
• Layout of the image may vary due to difference of the base
layout (relative, linear etc.)
Layout Creation:
• Focus was the MainActivity class this adds funtionality to the app, to always keep in mind
the name of the activity, which is showen as package com.example.activityname
• This class will always declare attributes, such as public class and then the activity name, which
helps inform the coder identify the variables.
• Defining variable that represent the widgets help identify the specific widgets which are used
in the layout
Using UI Widgets:
• Initially before placing widgets, it is important to create XML layout and then to specify the
necessary attributes, such as android:id=”@+id/newID”, android:layout_width/height
• Then focus on developing the Java layout by defining all the attributes, which can vary from a
button to linear layout.
• The Java layout should have data type, type casting and return a generic view object.
• Finally implement the widgets wihtin Java by configuring UI elements with usign the get and
set methods, this allows user to create a specific action to their widgets.
Toggle button, allows options for users with
an indicator highlighting the option selected Radio buttons allows users select from
variety of options as these are presented in a
circular shaped element and the selected
option would be highlighted in a colour
SIT207 ANDROID PROGRAMMING PORTFOLIO 22
Activity:
• This is summarized as a single thing that the user is able to do, it provides the user screen to
the user who is able to interact
• Each activty in presented in an assigned window as the content on the window is
implemented in subordinate views.
• An activity lifecycle is a set of states and methods performed at each state, where the
android OS notices user when there is change of activity.
• Multiple activities can also be started, where an application can have multiple activities that
users are able to move in and out
• However, an application always starts with a main activity.
Intent:
• These are messages which allow android component to request functionality from other
components of the android system.
• These are essential in requesting information, computing and event signalling.
• This implemented on android studio like this, android.content.Intent
Manifest.xml:
• Every application contain the this file as it significant to have this in the application
• This present very essential information about the system application, as these information
can be essential in running the application
• Application should declare everything to the androidmanifest.xml file
Practical Activities
Practical tasks for this week covers things that are essential in UI development which are,
• Learn to insert portrait and landscape layouts
• The use of Intent
• The use of the action bar
• Creating a list dialog
The tasks done will demonstrate the layout changes and the implemented process when the layouts
are specified to look in variety of view, such as portrait and landscapes. We also covered the
These two views
demonstrates the views
that will be presented
within assigned window
SIT207 ANDROID PROGRAMMING PORTFOLIO 23
implementation process of the format of the code and the scripts on how to define to specific
attributes.
The process will result in the producing two view which are first and second view, which the aim
being when the button is clicked it transitions to the next frame or view.
The result of which produces the first view of the first activity which include the action button to
transition to the next view/frame.
As for now the button is not active as it is not link
to the next frame, it is yet to be created.
SIT207 ANDROID PROGRAMMING PORTFOLIO 24
This creates the second view layout which allows transition back to the first activity and java code
used allows the transitions, which is public void GoToSecondActivity(View v).
Gotosecond allows the interaction between
the two frames, which it simply just
proceed to the next screen with the click of
the button
SIT207 ANDROID PROGRAMMING PORTFOLIO 25
This will modify the existing layout code to display the layout in landscape format when the phone is
flipped to horizontal view.
The code below demonstrates the use of intent filter and defining strings to specific views.
The code is similar to above the
only difference being the value of
the margin top set at 90dp
Every defined strings are processed
from here as in the code you can refer
to a specific string with an @ sign
The intent filter usage applies to the
action of the main and category
based launcher
SIT207 ANDROID PROGRAMMING PORTFOLIO 26
This is the final view of the completed two view layouts which are functional via clicking button of
that specific activity.
The final layout views of the two screens which
will transition between them if the buttons are
clicked as this is the basic aim of this
demonstration
SIT207 ANDROID PROGRAMMING PORTFOLIO 27
Week 5 Summary
Recap
We covered the significance of intent, which basically can be defined as bundle of information as it
contains information of interest the component that receives the intent. We also addressed the
implementation of the intent as to how to process it on the android studio. Stack was also on the
agenda as they basically the activities which are organised and displayed in a form information
stacks but these activities arranged in the order of when it is opened.
The other significant aspect of coding was bundle class which allows data to be stored using key
value pair. This function will essential in helping passing data using intent as this can prove to be
useful when developing a game functionality, which some games keeps record of player data. We
addressed intent but there is also implicit and explicit intent which are slightly different to intent. As
always we addressed the importance of the manifest.xml file as it present essential information on
the application.
Things Learnt
Intent:
• Bundle of information
• Information on the components that receives intent and information that interest the
android system
• Action to be taken and the data to act upon the specific action
• Simple message which communicate which the android components such as activities.
• This is also used to transfer data between activities.
Implicit Intent:
• These must know the action type they want to be done for them
• You define the action that you want to perform for different activities
• It specifies an action that can invoke any app on the device to be able to perform the
actions.
• This can be useful when your app cannot perform the action you request but the other apps
are able to perform, they are also useful in re-using code and launching external applications
• These do not specify a components as they must include enough information for the system
to determine which available components I best suited to run the intent.
Explicit Intent:
• These explicitly define the component
that needs to be called by the Android
system, meaning that the system
defines components at default.
• It can be used to launch a specific app
component, such as a particular
activity or service in your app.
SIT207 ANDROID PROGRAMMING PORTFOLIO 28
Stacks:
• The activities are arranged in a stack, which are called task, in the order in which each
activity is opened.
• When the current activity starts another, the new activity is pushed on the top of the stack
and takes focus. The previous activity remains in the stack, but is stopped.
• Can be also defined as data structure, which is the structure of which the data displayed.
Some commonly used intent and
functionality of each one the
action
Some of the intent used and that implementation
process of intent in android
A basic stack that allows
displays the structure of the
data.
SIT207 ANDROID PROGRAMMING PORTFOLIO 29
Bundle:
• Basically the allows you to store data
• Each stored data can be altered and modified by user depending the defines attributes
Intent Filter:
• This can be described as the actions or services that an activity can perform and the types of
data that an activity is able to process.
• Each of these filters are defined and displayed by an <intent-filter> element in the manifest
file of the app.
• A single <intent-filter> may include more than one <action>, <category> and <data>. In this
case the target component must be able to handle any or all combination of Intents.
• To allow several specific combinations of these you must define multiple intent filters.
Practical Activities
There were no practical activities for this week
Data passing through use of bundle
and implementation process of
compiling data together
Different usage of the intent process
and the purpose and functions are
demonstrated here
SIT207 ANDROID PROGRAMMING PORTFOLIO 30
Week 6 Summary
Recap
This is week focus was on list view which is significant in developing UI as we covered the
importance and the significant difference between the default and customised list view. There are
different attributes that unique each of the view layouts which perform differently depending on the
specifications. The custom view and working with view were also addressed as different view and
layout will respond differently to the functionality and points out ways to implement these to a
specific standard.
Event handling was also addressed as this concept is also significant in the functionality of app
development, which provides vital purpose of handling when a significant new event occurs in the
script. The purpose the event handler in vital as it helps in handling event with the code that can be
new or specified by the user to check or can be detected by the system if there were to have a new
event exist in script.
Things Learnt
ListView:
• Android studio enables user to create or view list view
• List view is scrollable, which display number of items in one list, this is useful as it also allows
to provide further details on particular item.
• This view considered to be most commonly used in developing and designing UIs
• Creating the list involves writing code and script which can be user defined
• The created list can be modified and altered to different specification to suit different
designs
Able to present detailed
information with description
with list view such as this, as
details are significant to users
SIT207 ANDROID PROGRAMMING PORTFOLIO 31
• The screen shown above demonstrate the customised list view which are modified and
contains user defines values and attributes
• Shows that the customised list view system provided different functionality and layouts
String[] value = new String[], this allows the user to
define variable of their choice, it will display the list
in simple list form. It will ensure the list is displayed
the defined variables
This will display a costumed view list display as the
attributes of these element is user defined and
displayed to specific layout.
Each defined layout should contain an android id
which can help identify which layout is being
developed.
SIT207 ANDROID PROGRAMMING PORTFOLIO 32
Adaptor:
• ArrayAdaptor use TextView to represent the list item
• SimpleCursorAdaptor used with SQLite databases and content providers by converting
cursor row to list items.
• Adaptor can be implemented by ArrayAdapter<String> adapter = new
ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values);
• User setListAdapter() to inflate the list view using the adapter
• If the user select in the list a list entry the method onListItemClick() will be called. This
method allows to access the selected element.
View Class:
• This class is the base class for widgets which are used to create interactive UI componets
such as buttons, text fields, radio buttons etc.
• It will understand the widgets and how they are presented in the app
• Represent the basic builing blcok for UI components
• This occupies a rectangular area on the screen and is responsible for drawing and event
handling
• Implementation fo view class is achieved by,
o Extend view cass or is subclass
o Override some mehods, suchas draw view onDraw() and event handling
onTouchEvent()
• Use the new in your layout
• Below shows the implementation process of which the view class can be processed with the
The use of adaptor array can
be implement through this
code and the script
SIT207 ANDROID PROGRAMMING PORTFOLIO 33
The override the callback function method consists of
two sub-processes, draw and event handling
protected void onDraw(Canvas canvas), this method
gives a canvas object on which to you can draw your
view
public boolean onTouchEvent (MotionEvent event)
interprets the touch event of the activity and can
identify the touch pattern on the screen
The use the view as content of the activity, as this will allow
the view to displayed within the content.
MyCustomView myCustomView = new MyCustomView(this);
setContentView(myCustomView);, this will display the user
costumed view to the layout, the view will display the
content.
This the view class which is implemented through
overriding some methods,
public class MainActivity extends Activity, this define
the activity class which is the main body class of the
process
class MyCustomView extends View allows to view
costumed class, which can be specified to some action
or acting upon an action
SIT207 ANDROID PROGRAMMING PORTFOLIO 34
Practical Activities
The focus for this week was developing UI and debugger, which consists of,
• Development of UI and Listeners
• The use of the Android Debugger
• Using the Android Hotkeys
The development of UI and the use of debugger is demonstrated within the following activity as it
shows the use of UI elements and running the app through debugger to help identify any significant
errors or bugs that may cause the app not to function properly.
This creates the main UI design which displays all
the content, as for this purpose it will display
numbers in the text fields which is defined by
the input type
In the code we have defined all the variables which
corresponds to all the UI elements defined in the
design as this will calculate sum between two
numbers
SIT207 ANDROID PROGRAMMING PORTFOLIO 35
The result of the above code gives the following output of the design which we managed create.
Original displays of
which we created as
this is how it will be
displayed
When the design is processed and run through the emulator, this is what will
be displayed which the user will type a number in which the automated
number pad will pop up which helps the users types two number in the first
two field in which the result will be calculated displayed in final field.
SIT207 ANDROID PROGRAMMING PORTFOLIO 36
Week 7 Summary
Recap
The key focus for this week was persistence which is defined as the continuance of an effect after its
cause is removed, although in the computing field it refers to data surviving after the process with
which it created has ended. We also covered saving data in android as there are number of ways in
which android allows the data to stored and using the right method of data storing is essential.
The primary topics covered for this week involves of storages and the types of storages and ways to
implement these in android studio. Apart from these we touched the android debugging but the
lecture mostly involves the storage techniques which are significant but each method defines
differently when implemented within a process. We also address the SQL database which can be
essential in development the app in which to store specific data content.
Things Learnt
Persistence:
• It does not change as is not somethings that is accessed regularly
• Contain essential information that categorised as significant data
• Data that is stored in an actual format and that will stay there unless told otherwise
• Non-volatile
• When stored it will remain in one location for extended period of time as the data will not
change at all.
• Guaranteed durability with the comings and goings of new devices and data can be
recovered
• Be confident that the changes to the data will not be lost and available for later use.
Persistence Issue:
• When orientation of the screen is changed, the activity is destroyed and opened again
• Data can be stored with onSaveInstanceState(Bundle) and be read with
onRestoreInstanceState(Bundle), although this is held temporary
Shared Preferences:
• Lightweight mechanism to store private primitive data in key value pairs in hard drive.
• A general framework that allows you to save and retrieve persistent key-value pairs of
original data types and strings.
• This data will persist across user sessions even if the application were to crashed or killed.
• Data types such as user name, password, email address or high scores can be stored in
shared preferences.
SIT207 ANDROID PROGRAMMING PORTFOLIO 37
• As shown above the getSharedPreferences attribute is defined with a string name and an int
mode. Read and write modes of this particular attributes is also mentions as the use of the
editor is an essential for this process.
Storage:
• Internal storage is for private data, by default files save to this are private as they restrict
access to other applications, although files will be deleted if users uninstalls applications.
• External storage are for publicly shared where it support multiple devices and is able to
access them from any device as this type of storage come in all form of hardware, such as
USBs, SD cards etc.
Storing files involves the writing a
file then read making sure to also
close the files as shown, also file
choosing file modes involves the
android.content.Context line in the
Java script
SIT207 ANDROID PROGRAMMING PORTFOLIO 38
SQLite:
• Implements lightweight SQL database engine and is the most widely used SQL database in
the world
• It is embedded in android as it is open source database and available on every android
device, however SQL statements must be defined for creating and updating the database.
• This technique has method to create, delete, execute SQL commands and perform other
common database
• The only negative of this concept would be that it only allow 2GB for the database size most
of the time.
Database:
• Collection of organised data which is stored in a database as it can be modified and alter
with implementation of database techniques.
• The table consists to row and columns which can altered and modified to suit specific data
entries, as each data collection is broken to fields.
This code demonstrate the SQL implementation and
the implementation of the SQL command in the
android studio, as there is only minor difference in
executing the code in Android.
This method will insert the data in
the database, each of the attributes
are defined to their corresponding
elements in which the data will be
displayed with right context
SIT207 ANDROID PROGRAMMING PORTFOLIO 39
Practical Activities
The practical tasks for this week involves the development of more UI design and functionality
element in will provide much more dynamic look and feel of a particular app. We covered,
• Using Lists in Android
• Custom Adaptor Implementations
The task below involved the use of list view and list activity, but with more functionality on providing
specific action, it also involves of creating array adaptor to the display and view the list view.
This creates list using array adaptor as it
can define how the layout is displayed
in this case we created row layout. The
purpose of which is converts an list of
objects into view items loaded into a
list container
SIT207 ANDROID PROGRAMMING PORTFOLIO 40
The tasks done below demonstrate the developing the same task with the same functionality,
however we have implemented custom array adaptor.
Week 8 Summary
Recap
We discussed significant concept in android, which will help develop applications in handling certain
situations. The main concept of process vs threads are essential in the development of an
application as the focus for this week was primarily on multi-threading. We also covered the
techniques used to handle specific message and significance of handler loop messages. Examples of
each of these techniques and concepts being used was also demonstrated throughout the lecture
these demonstrations prove to be essential in developing a functional application.
Things Learnt
Timesharing Operating Systems:
• Enables users to use specific system in a computer at the same time.
• Allows users to multi task as the same time.
• Process within the system are mainly managed by the system, some being handled or
executed by user.
• System switches between threads and processes fast so that it appears to be multiple
process running is on a single process system.
• Parallel processing and threads allocated across processors is on multi-core or multi-
processor system.
Process:
• Defined as an execution of a single program on a computing device
• Scheduled by the OS and owned by user or the OS
• They can have a long lifetime (a web server) or a short lifetime (one run of a short program)
• These don’t share memory between each other as most OS support inter-process
communication.
SIT207 ANDROID PROGRAMMING PORTFOLIO 41
• This can be initiated or terminated by a user or another program and can also be a program
running in the background of a computer.
Thread:
• Can be described as a component of
a process.
• Considered the smallest unit that can
be planned by an OS.
• Ability to share memory and
instruction with other threads in the
same process and support inter-
thread communication.
• Set of instructions that is
programmed which can be managed
individually by a part of an OS.
• Share executable code and values,
which can simply be a running code
or a written program.
Timer Thread:
• This a runnable object, this calls schedules
tasks for one-time execution or for situation
that repetitive at regular intervals
• The java.util.Time, provides facility for thread
to plan tasks for future execution in a
background thread
• Used by thread to plan a task, such as running a code, each time object is associate with a
background thread that is responsible for execution of all tasks
• Can be used with timer(), timer(boolean isDaemon), timer(String name) or time(String
name, boolean isDaemon).
• Timer class used is shown in the example below,
import java.util.Timer; import java.util.TimerTask; class Helper extends TimerTask { public static int i = 0; public void run() { System.out.println("Timer ran " + ++i); } } public class Test { public static void main(String[] args) { Timer timer = new Timer(); TimerTask task = new Helper(); timer.schedule(task, 2000, 5000);
SIT207 ANDROID PROGRAMMING PORTFOLIO 42
} }
Handler:
• Enables to send and process Message and Runnable object in relation with thread.
• As new Handler is created, it is bound to the thread and message queue of the thread.
• Delivers message and runnable to the message queue, which then it will execute them.
• For each activity only one handler is required.
Message Class:
• Defined as a message containing a description and random data object which can be sent to
a handler.
• Message.obtain() or Handler.obtainMessage() methods allows to gain access the message
constructor.
Multi-Threading:
• Able develop multi-threading programs
• Consists of two or more parts that are able to run in parallel and able to handle different
tasks
• Multiple process share common processing resources such as CPU
• Similar to multi-tasking, where it goes beyond of able to subdivide specific operations within
single application in individual threads.
• Enable to write in way where multiple activities can process in parallel within the same
program.
Practical Activities
This week practical focused on looking at how to use android SharedPreferences class to
store and retrieve application specific persistent data. The task involves of developing and
experimenting with an UI design to implement these functions with UI by adding functional buttons
that use these techniques.
First the method should be created to save data in SharedPreference object
SIT207 ANDROID PROGRAMMING PORTFOLIO 43
Method to retrieve data from SharedPreference object should be defined
Then the data in the SharedPreference object needs to be cleared
Specific key values can be removed
SIT207 ANDROID PROGRAMMING PORTFOLIO 44
References
• Freepik Company S.L. 2018, android free icon, flaticon.com, retrieved 3rd September 2018,
https://www.flaticon.com/free-icon/android_174836
• Tutorialspoint 2018, Java Multithreading, tutorialspoint.com, retrieved 3rd September 2018,
https://www.tutorialspoint.com/java/java_multithreading.htm
• GeeksforGeeks 2018, Java.util.Timer Class in Java, geekforgeek.org, retrieved 3rd September
2018, https://www.geeksforgeeks.org/java-util-timer-class-java/