0% found this document useful (0 votes)
294 views13 pages

Advances in Mobile Technology

Mobile technology refers to portable devices like smartphones, tablets, and PDAs that allow users to perform tasks via cellular networks. Examples of mobile technologies include Apple and Samsung smartphones, as well as tablets. Mobile technologies can be classified as either personal or shared, and either portable or static. Personal technologies like smartphones are portable, while shared technologies like interactive whiteboards are static. Future mobile devices may have always-on screens, fingerprint security, context awareness, and ability to access information by pointing a phone's camera. Mobile technology has changed the world in areas like education, agriculture, banking, health, and business.

Uploaded by

Suleiman Abdul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
294 views13 pages

Advances in Mobile Technology

Mobile technology refers to portable devices like smartphones, tablets, and PDAs that allow users to perform tasks via cellular networks. Examples of mobile technologies include Apple and Samsung smartphones, as well as tablets. Mobile technologies can be classified as either personal or shared, and either portable or static. Personal technologies like smartphones are portable, while shared technologies like interactive whiteboards are static. Future mobile devices may have always-on screens, fingerprint security, context awareness, and ability to access information by pointing a phone's camera. Mobile technology has changed the world in areas like education, agriculture, banking, health, and business.

Uploaded by

Suleiman Abdul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Lecture 01: Overview of Mobile Examples of smartphones: Apple iPhone, Samsung, Nokia,

Blackberry, Motorola.
Mobile Technology
Classification of mobile technologies
Mobile Technology simply means technology that is portable;
Mobile technology instils the image of personal, portable
it refers to any device that you can carry with you to perform
device, linked to the World Wide Web
a wide variety of “tasks”
(Naismith, et al., 2004) classify the range of mobile
It is technology that allows those tasks to be performed via
technology using the two orthogonal dimensions of personal
cellular phone, PDA, vehicles, laptops, etc
vs shared and portable vs static.
Mobile device has gone from being no more than a simple
two-way pager to being a cellular phone, a GPS navigation
system, a web browser, and instant messenger system, a
video gaming system, and much more.
It includes the use of a variety of transmission media such as:
radio wave, microwave, infra-red, GPS and Bluetooth to
allow for the transfer of data via voice, text, video, 2-
dimensional barcodes and more.
Types of Mobile Technology
Personal Digital Assistant (PDA)
They are sometimes called pocket computers. The four quadrants of the figure indicate the classification of
They are handheld devices that combine elements of the mobile technology.
computing, telephone/fax, Internet and networking in a The first quadrant (1) is the idea that mobile technology is
single device. portable and personal, and allows for networking and
A typical PDA can function as a cellular phone, fax sender, communication.
Web browser and personal organizer. It is probably atypical of mobile technology and the backbone
PDAs have largely been rendered obsolete by the rise in of m-learning. Personal and static learning (2).
popularity of smartphones and tablets. We have Classroom response systems, devices such as quizdom
Examples of PDA’s : Palm Pilot, Revo, Sony Clie, Hewlett- and the SMART response system to name a few.
Packard Jornado, Casio Cassiopedia, Compaq iPaq and Quadrant 3 refers to personal but shared mobile technology.
Toshiba Pocket PC. Being physically moved from one place to another is not the
Tablet PCs only way in which mobile technologies can be portable.
Tablet PCs are an evolution of the notebook computer with It is the person that is mobile and the “kiosk” is fixed.
touchscreen LCD screens that can be utilized with your Suggests such devices are typically seen as being less personal,
fingertips or with a stylus. and are likely to be shared between multiple users.
The handwriting with a stylus is digitized and can be Large devices such as interactive whiteboards and video
converted to standard text through handwriting recognition, conferencing, allow for a more sharable interactions and are
or it can remain as handwritten text. much less portable, as shown in quadrant 4.
The stylus can also be used to type on a pen-based key layout Mobile communication technologies
where the lettered keys are arranged differently than a Mobile devices can be enabled to use a variety of
QWERTY keyboard communications technologies such as:
may also offer a removable keyboard as an additional input − wireless fidelity (WiFi) - a type of wireless local area
option network technology
Examples: Apple iPad, Microsoft Surface and Surface Pro, − Bluetooth - connects mobile devices wirelessly
Samsung Galaxy Tab, Samsung Nexus and Amazon Kindle − ‘fourth generation’(4G),'third generation' (3G), global
Fire HD system for mobile communications (GSM) and general
Smartphones packet radio service (GPRS) data services - data networking
Smartphones combine a mobile phone and a handheld services for mobile phones
computer into a single device. − dial-up services - data networking services using modems
Smartphones allow users to access and store information and and telephone lines
install programs while also being able to use a mobile phone − virtual private networks - secure access to a private
in one device. network
A smartphone could be a mobile phone with some PDA Future of smart phones
functions integrated into the device or vice versa.
Always on screen so you are never in the dark

Page 1 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


Along with the future of a smart phone comes the future of − Limited capacity
another device. Omnitouch is a device in which applications − Poor handoff reliability
can be viewed and used on your hand, arm, wall, desk, or − Poor security
any other everyday surface. The device uses a sensor touch − Offered very low level of spectrum efficiency
interface, which enables the user to access all the functions Second Generation (2G)
through the use of finger touch. This device uses a projector 2G refers to the second generation based on GSM and was
and camera that is worn on the person's shoulder, with no emerged in late 1980s. It uses digital signals for voice
controls other than the user's fingers. transmission. Main focus of this technology was on digital
Fingerprint security signals and provides services to deliver text and picture
Context-aware, taking advantage of the growing availability message at low speed (in kbps)
of embedded physical sensors and data exchange abilities. It use the bandwidth of 30 to 200 KHz. Next to 2G, 2.5G
Phones will start keeping track of your personal data, but system uses packet switched and circuit switched domain and
adapt to anticipate the information you will need based on provide data rate up to 144 kbps. e.g. GPRS, CDMA and
your intentions. EDGE
X-Ray device that reveals information about any location at The main features of 2G and 2.5G are:
which you point your phone. Companies want to make the Second generation, 2G
phone a virtual mouse able to click the real world. An example − Data speed was up to 64kbps
of this is where you can point the phone's camera while having − Use digital signals
the live feed open and it will show text with the building and − Enables services such as text messages, picture messages and
saving the location of the building for use in the future. MMS(Multimedia message)
Ways mobile technology has changed the world − Provides better quality and capacity
Key areas where mobile technology has had the greatest − Unable to handle complex data such as videos.
success: − Required strong digital signals to help mobile phones work.
− Education If there is no network coverage in any specific area, digital
− Agriculture signals would weak.
− Banking Second generation, 2.5G
− Health − The GSM technology was continuously improved to provide
− Business better services which led to development of advanced

Mobile communication technologies Technology between 2g and 3g

Mobile communication has become more popular in last few − Provides phone calls

years due to fast reform from 1G to 5G in mobile technology. − Send/receive e-mail messages

This reform is due to requirement of service compatible − Web browsing

transmission technology and very high increase in telecoms − Speed : 64-144 kbps

customers. Generation refers change in nature of service − Camera phones

compatible transmission technology and new frequency − Take a time of 6-9 mins. to download a 3 mins. MP3 song.

bands. In 1980 the mobile cellular era had started, and since Third Generation (3G)
then mobile communications have undergone considerable 3G is based on GSM and was launched in 2000. The aim of
changes and experienced massive growth. this technology was to offer high speed data. The original

First Generation, 1G technology was improved to allow data up to 14 Mbps and

These phones were the first mobile phones to be used, which more using packet switching.

was introduced in 1982 and completed in early 1990. It was It uses Wide Band Wireless Network with which clarity is

used for voice services and was based on technology called as increased.

Advanced Mobile Phone System (AMPS). It also offers data services, access to television/video, new

The AMPS system was frequency modulated and used services like Global Roaming.

frequency division multiple access (FDMA) with a channel It operates at a range of 2100MHz and has a bandwidth of

capacity of 30 KHz and frequency band of 824- 894MHz. 15-20MHz used for High-speed internet service, video

Its basic features are: chatting.

− Speed-2.4 kbps The main features of 3G are:

− Allows voice calls in 1 country − Speed 2 Mbps

− Use analog signal. − Typically called smart phones

− Poor voice quality − Increased bandwidth and data transfer rates to

− Poor battery life accommodate web-based applications and audio and video

− Large phone size files.

Page 2 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


− Provides faster communication − Multi-media newspapers, watch TV programs with the
− Send/receive large email messages clarity(HD Clarity)
− High speed web/more security/video conferencing/3D − Faster data transmission that of the previous generation
gaming − Large phone memory, dialing speed, clarity in audio/video
− Large capacities and broadband capabilities
− TV streaming/mobile TV/Phone calls
− To download a 3 minute MP3 song only 11 sec-1.5 mins
time required.
− Expensive fees for 3G licenses services
− It was challenge to build the infrastructure for 3G
− High bandwidth requirement
− Expensive 3G phones
− Large cell phones
Fourth Generation (4G)
4G offers a downloading speed of 100Mbps. 4G provides
same feature as 3G and additional services like Multi-Media
Newspapers, to watch T.V programs with more clarity and
send Data much faster than previous generations.
LTE (Long Term Evolution) is considered as 4G technology.
4G is being developed to accommodate the QoS and rate Mobile operating systems
requirements set by forthcoming applications like wireless A mobile operating system (OS) is software that allows
broadband access, Multimedia Messaging Service (MMS), smartphones, tablet PCs and other devices to run applications
video chat, mobile TV, HDTV content, Digital Video and programs.
Broadcasting (DVB), minimal services like voice and data, and A mobile OS typically starts up when a device powers on,
other services that utilize bandwidth presenting a screen with icons or tiles that present
The main features of 4G are : information and provide application access many Mobile
− Capable of provide 10Mbps-1Gbps speed Operating systems.
− High quality streaming video Mobile operating systems also manage cellular and wireless
− Combination of Wi-Fi and Wi-Max network connectivity, as well as phone access.
− High security Most mobile operating systems are tied to specific hardware,
− Provide any kind of service at any time as per user with little flexibility
requirements anywhere Types of Mobile Operating Systems
− Expanded multimedia services Apple iOS
− Low cost per-bit Google Android
− Battery uses is more Research in Motion’s BlackBerry OS
− Hard to implement Nokia’s Symbian
− Need complicated hardware Hewlett-Packard’s webOS (formerly Palm OS)
− Expensive equipment required to implement next Microsoft’s Windows Phone OS.
generation network Microsoft’s Windows 8, function as both a traditional desktop
Fifth Generation (5G) OS and a mobile operating system.
5G refer to Fifth Generation which was started from late iOS
2010s. Is a mobile operating system created and developed by Apple
Facilities that might be seen with 5G technology includes far Inc, exclusively for its hardware. It is the operating system
better levels of connectivity and coverage. that presently powers many of the company's mobile devices
The main focus of 5G will be on world-Wireless World Wide The iOS user interface is based upon direct manipulation,
Web (WWWW). using multi-touch gestures. Interface control elements consist
It is a complete wireless communication with no limitations of sliders, switches, and buttons
The main features of 5G are: The first was developed in 2007, since then 12 more iOS was
− It is highly supportable to WWWW (wireless World Wide developed. iOS 12.1.4 is the latest iOS software
Web) Closed source OS
− High speed, high capacity Objective C
− Provides large broadcasting of data in Gbps. Development environment of iOS is apple Xcode which runs
only on MAC systems.

Page 3 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


Blackberry Android Versions
Formally known as research in motion (RIM)
The first blackberry device (email pager) was released in
1999.The most powerful that is multitasking and supports
unique input devices like trackwheel, trackpad, trackball and
touch screen
C/C++ was formerly used for development and then java. Now
applications can be developed using c/c++/Qt,
javascript/html/css and java Android skills
Windows Phone
Mobile OS created by Microsoft was called Windows Mobile.
After the changes introduced by Apple (iOS) and Google
(Android) in 2007, Microsoft decided to take a new direction
and created Windows Phone.
It is an operating system for smartphones used on touch Features of Android
screen devices, and offers functionality such as networking, 3-D graphics: The interface can support 3-D graphics for a
sensors and camera integration. 3-D interactive game experience or 3-D image rendering.
Programs for Windows Phone 7 are written in .NET managed Facial recognition: Android provides this high-level feature
code such as C# for automatically identifying or verifying a person’s face from
It supports two popular programming platforms, namely a digital image or a video frame.
Silverlight and XNA Front- and rear-facing camera: Android phones can use
Firefox OS either a front- or rear-facing camera, allowing developers to
It represents a new generation of mobile operating systems, create applications involving video calling.
namely a web based OS Multiple language support: Android supports multiple human
It is designed based upon open standards and approaches languages.
from HTML5 applications, JavaScript and web APIs. On-screen keyboard: The on-screen keyboard offers
Firefox OS was first demonstrated public in early 2012, suggestions for spelling corrections as well as options for
running on an Android based phone completing words you start typing. The on-screen keyboard
Demonstrated on raspberry pi and mozilla in 2013 also supports voice input.
Android OS Power management: Android identifies programs running in
Released by Google in 2007 the background using memory and processor resources. You
It is open source and developed on the Linux kernel. can close those apps to free up the phone’s processor memory,
It is based on Java and XML and so native applications are extending the battery power.
developed with java programming language and XML using For optimized gaming: Android supports the use of a
the developed Google java libraries gyroscope, gravity and barometric sensors, linear
Development environments for android applications include acceleration, and rotation vector, which provide game
tools like Eclipse ADT bundle, Intellij IDEA and android studio developers highly sensitive and responsive controls.
BETA Voice-based recognition: Android recognizes voice actions for

Introduction to Android Programming calling, texting, and navigating with the phone.
Wi-Fi Internet tethering: Android supports tethering, which
What is android?
allows a phone to be used as a wireless or wired hot spot that
Based on modified version of Linux which is open and free
other devices can use to connect to the Internet.
Most of android code was developed under the open source
Apache License.
Android Architecture

This property of android makes it possible for manufacturers


to design their own hardware and use Android as the
operating system that powers it.

Page 4 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


The Android OS is roughly divided into five sections in four The emulator mimics almost every feature of a real Android
main layers: handset except for the ability to place a voice phone call.
1. Linux kernel — this is the kernel on which Android is based. A running emulator can play video and audio, render gaming
This layer contains all the low-level device drivers for the animation, and store information.
various hardware components of an Android device. Multiple emulators are available within the Android SDK to
2. Libraries — these contain all the code that provides the target various devices and versions from early Android phones
main features of an Android OS. For example, the SQLite onward.
library provides database support so that an application can Market Deployment
use it for data storage. The WebKit library provides After you write and test a program, you compile the app into
functionalities for web browsing an Android package file with the filename extension .apk.
3. Android runtime — at the same layer as the libraries, the Programs written for the Android platform are sold and
Android runtime provides a set of core libraries that deployed through an online store called Google Play
enable developers to write Android apps using the Java (play.google.com).
programming language. The Android runtime also includes It provides registration services and certifies that the
the Dalvik virtual machine, which enables every Android program meets minimum standards of reliability, efficiency,
application to run in its own. Dalvik is a specialized virtual and performance.
machine designed specifically for Android and optimized for Google Play requires that you sign an agreement and pay a
battery-powered mobile devices with limited memory and one-time registration fee (currently $25).
CPU. After registration, you can publish your app on Google Play,
4. Application framework — exposes the various capabilities of provided the app meets the minimum standards. You can also
the Android OS to application developers so that they can release updates as needed for your app.
make use of them in their applications. If your app is free, Google Play publishes your app at no cost.
5. Applications — At this top layer, you will find applications If you want to charge for your app, the standard split is 70
that ship with the Android device (such as Phone, Contacts, percent of sales for the developer and 30 percent for the
Browser, etc.), as well as applications that you download wireless carriers.
and install from the Android Market. Any applications that
Creating a new Android Project
you write are located at this layer.
To create the new project, simply click on the Start a new
Android Devices in the market Android Studio project option to display the first screen of
Smartphones the New Project wizard
Tablets
E-reader devices
Netbooks
MP4 Players
Internet TVs
Smart Glasses

Obtaining the Required Tools


Java jdk
Android sdk: The Android SDK includes a set of development
tools that help you design the interface of the program, write
the code, and test the program using a built-in Android
handset emulator. It contains the debugger, libraries, an
In the New Project window, set the Application name.
emulator, documentation, sample code and tutorials)
Android studio (it contains the sdk).
Android apps are written using the Java programming
language.
Another language called XML (Extensible Markup Language)
is used to assist in the layout of the Android emulator.
Android Emulator
The Android emulator lets you design, develop, prototype,
and test Android applications without using a physical device.
When you run an Android program in Android Studio, the
emulator starts so you can test the program. You can then
use the mouse to simulate touching the screen of the device.
Page 5 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba
The application name is the name by which the application
will be referenced and identified within Android Studio and
is also the name that will be used when the completed
application goes on sale in the Google Play store.
The Package Name is used to uniquely identify the application
within the Android application ecosystem.
Click Next to proceed. On the form factors screen, enable the
Phone and Tablet option and set the minimum SDK setting
to API 8: Android 2.2 (Froyo).
A useful chart can be viewed by clicking on the Help me choose
link.

ANATOMY OF AN ANDROID APPLICATION


AndroidManifest.xml — this is the manifest file for your
Android application. The AndroidManifest.xml file contains
detailed configuration information for your application. Here
you specify the permissions needed by your application, as
well as other features (such as intent-filters, receivers, etc.)
Java— contains the .java source files for your project.
Res — this folder contains all the resources used in your
application. It also contains a few other subfolders: drawable-
Creating Activity <resolution>, layout, and values.
Select blank activity and click next Main Window

Name the activity and title androidSampleActivity.


Elements of Android studio window
Click finish to initiate the project creation process
A – Menu Bar – Contains a range of menus for performing
The newly created project and references to associated files
tasks within the Android Studio environment.
are listed in the Project tool window located on the left hand
B – Toolbar – A selection of shortcuts to frequently
side of the main project window.
performed actions. The toolbar buttons provide quicker access
to a select group of menu bar actions

Page 6 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


C – Navigation Bar – The navigation bar provides a Designing the User Interface Layout within the Virtual
convenient way to move around the files and folders that Device
make up the project. To assist in designing the Android user interface, the Android
D – Editor Window – The editor window displays the content SDK includes layout files.
of the file on which the developer is currently working. You can create a layout and then add widgets to the layout.
E – Status Bar – The status bar displays informational A layout is a container that can hold as many widgets as
messages about the project and the activities needed.
F – Project Tool Window – The project tool window provides A widget is a single element, also called an object, such as a
a hierarchical overview of the project file structure allowing TextView, Button, or CheckBox control.
navigation to specific files and folders to be performed By default, a TextView widget displays the text Hello World
Creating android virtual devices (AVD) within the emulator.
To create an AVD, select Tools -> Android -> AVD Manager The Properties pane to the right of the emulator contains
in the menu option the properties and settings of the currently active Android
app project or object.
A property describes what an object can do; for example, if
you change the text property of a TextView object, the
updated text is displayed in the emulator.

Layouts
The Android user interface includes a layout resource designer
that organizes how controls appear on the app’s various
screens. There are several layouts available in android:
Relative Layout
LinearLayout
TableLayout
GridLayout
FrameLayout
Relative layout
Click on the Create a virtual device button in order to invoke
It organizes layout components in relation to each other as
the Virtual Device Configuration dialog
shown.
In the Virtual Device configuration dialog, select the
This provides more flexibility in positioning controls than
appropriate options.
other layouts.
Give it a name
Click finish
To perform a test run of the newly created AVD emulator,
simply select the emulator from the AVD Manager and click
on the launch button (the green triangle in the Actions
column).

Building the User Interface


Android supports two ways of building the user interface of
an application:
− Through Java code
− Through XML layout files
The XML method is preferred as it allows you to design the
user interface of an application without needing to write large
amounts of code.
Modifying the User Interface
Linear Layout
The user interface design for our activity is stored in a file
It organizes layout components in a vertical column or
named activity_android_sample.xml which, in turn, is located
horizontal row.
under app -> res -> layout in the project file hierarchy.
A Linear layout (vertical) places each control directly below
Double click on the file
the previous control to form a vertical column. If you select a
Here you can change and any view element to create the user
vertical Linear layout and drag the images onto the emulator,
interface of the activity
the images are arranged vertically in multiple rows

Page 7 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


A Linear Layout (Horizontal) Places each control side by side known as an activity’s life cycle. Understanding the life cycle
on a single row. of an activity is vital to ensuring that your application works
Linear layouts are common for forms that display controls in correctly.
a single row or column. Activity Life Cycle
Widgets
TextView
EditText
Button
ImageButton
CheckBox
ToggleButton
RadioButton
RadioGroup

The TextView view is used to display text to the user. This is


the most basic view and one that you will frequently use when
you develop Android applications. If you need to allow users
to edit the text displayed, you should use the subclass of
TextView, EditText.
Button — Represents a push-button widget
The Activity base class defines a series of events that govern
ImageButton — Similar to the Button view, except that it
the life cycle of an activity. The Activity class defines the
also displays an image
following events:
EditText — A subclass of the TextView view that allows users
− onCreate() — Called when the activity is first created
to edit its text content
− onStart() — Called when the activity becomes visible to the
CheckBox — A special type of button that has two states:
user
checked or unchecked
− onResume() — Called when the activity starts interacting
Example of a LinearLayout XML with some Widgets with the user
− onPause() — Called when the current activity is being
paused and the previous activity is being resumed
− onStop() — Called when the activity is no longer visible to
the user
− onDestroy() — Called before the activity is destroyed by the
system (either manually or by the system to conserve
memory)
− onRestart() — Called when the activity has been stopped
and is restarting again
Coding the Java Activity
The onCreate method is where you initialize an Activity
The syntax for the onCreate method is
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
For a particular user interface to open on the screen, code
must be added inside the onCreate method to place that
specific activity on top of the stack. The Java code necessary
to display the content of a specific screen is called
setContentView.
Activities setContentView(R.layout. main);
An activity is a single, standalone module of application Creating a Button Event Handler
functionality that usually correlates directly to a single user When a user taps the Button control, the event triggered is
interface screen and its corresponding functionality. Each a click event in java.
application can have one or more activities. For a button to be activated, the java code must contain
From the moment an activity appears on the screen to the OnClickListener( ) method to await the button click action
moment it is hidden, it goes through a number of stages, onClick( ) method to respond to the click event

Page 8 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


Each view in the xml is given a unique id using the property b.setOnClickListener( new OnClickListener() {

id. android:id=“ @+id/btnDisplay” public void onClick(View v) {


Toast.makeText(MainActivity.this,“Hello”,Toast.LENG
To handle the events fired by each view, you first have to
TH_LONG).show();
programmatically locate the view that you created in your }
});
xml. You do so using the findViewById() method (belonging to
theActivity base class), supplying it with the ID of the view: }
Button b = (Button findViewById(R.id.btnDisplay); Another way of programming views
Creating a Button Event Handler(2) Using the Button as an example, you can add an attribute
After the Button property is referenced in java file, an called onClick to it:
OnClickListener( ) method is necessary to detect when the <Button android:id=”@+id/btnSave”
android:onClick=”btnSaved_clicked”/>
user taps an onscreen button
The onClick attribute specifies the click event of the button.
The setOnClickListener() method registers a callback to be
The value of this attribute is the name of the event handler.
invoked later when a view is clicked.
Therefore, to handle the click event of the button, you simply
need to create a method called btnSaved_clicked

public void btnSaved_clicked (View view) {


Toast.makeText(MainActivity.this,“Go“,Toast.LENGTH_
LONG).show()
}
Radio Button and Radio Group

The onClick() method is called when the view is clicked RadioButton controls are used to select or deselect an option.
Each RadioButton control has a label defined by the Text
Creating a Button Event Handler(3)
property and a Checked property set to either true or false.
In the Package Explorer, double-click Main.java to open its
RadioButton controls are typically used together in a
code window. Click to the right of the
radioGroup.
setContentView(R.layout.main); line. Press the Enter key. To
Checking one radio button unchecks the other radio buttons
initialize and reference the Button control with the Id name
within the group.
of b, type
Example
Button b =(Button) findViewById(R.id.btnOpen);
Suppose you are to develop a medical app with an
Press the Enter key. To code the button listener that awaits
EditText(patients weight) control, a RadioGroup containing
user interaction, type b.seton and then wait for a code listing
two RadioButtons(convert pound to kg and kg to pound) and
to open. Double-click the first setOnClickListener to select it.
a Button (weight conversion)
In the parentheses, type new View .Double-click the first
Solution
choice, which lists an OnClickListener with an Anonymous
Each of the RadioButton controls placed on the emulator
Inner Type event handler.
need to be referenced by using the findViewById Java
Type ; (semicolon) after the closing parenthesis to complete
command.
the auto-generated stub.
final RadioButton lbsToKilo = (RadioButton)
Toasts findViewById(R.id.radLbToKilo);
final RadioButton kiloToLbs = (RadioButton)
A toast provides simple feedback about an operation in a findViewById(R.id.radKiloToLb);
small popup. After the RadioButton controls have been referenced, the
It only fills the amount of space required for the message and next priority is to determine which of the two radio buttons
the current activity remains visible and interactive. the user selected.
Toast object can be intiated with one of the makeText() If the user selected the Convert lbs to Kg radio button, the
methods. This method takes three parameters: the weight entered is divided by 2.2, but if the user selected the
application Context, the text message, and the duration for Convert Kg to lbs radio button, the weight is multiplied by
the toast. It returns a properly initialized Toast object. You 2.2.
can display the toast notification with show() Variable named conversionRate is assigned the decimal value
Toast.makeText(context, text, duration).show(); 2.2. The variables weightEntered and convertedWeight
E.g contain the patient weight and converted weight result,
Toast.makeText(MainActivity.this,“Hello”,Toast.LENGTH_LO respectively.
NG).show(); In the Package Explorer double-click Main.java to open the
Expected java code code window. Click after the comment line: /** Called when
public void onCreate(Bundle savedInstanceState) { the activity is first created. */. Press the Enter key to insert
super.onCreate(savedInstanceState);
setContentView(R.layout. main); a new blank line.

Button b = (Button)findViewById(R.id.btnOpen);

Page 9 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


− To initialize the conversion rate value of 2.2, type double Once displayed unfold the hierarchy by clicking on the right
conversionRate = 2.2;. facing arrows next to the entries in the Project window.
− Press the Enter key. To initialize the weightEntered The objective here is to gain access to the app -> java ->
variable, type double weightEntered; and com.example.layoutsample folder in the project hierarchy.
− press the Enter key. To initialize the variable that will hold Once the package name is visible, right-click on it and select
the converted weight, type double convertedWeight; Press the New -> Activity -> Blank Activity
the Enter key. In the resulting New Activity dialog, name the new activity,
− Click at the end of the line setContentView(R.layout.main);. the layout and the menu resource.
Press the Enter key. In order for an application to be able to run on a device it
− To initialize and reference the EditText class with the Id needs to have an activity designated as the launcher activity.
name of txtWeight, type final EditText weight = (EditText) Intents
findViewById(R.id.txtWeight);. The intent filter name of the new activity is used by the other
− Point to the red curly line under EditText and press alt + activities to invoke the new activity
enter When the button is clicked you use the startActivity()
− To initialize and reference the RadioButton class with the method to display SecondActivity
Id name of radLbToKilo, type public void onClick(View view) {
final RadioButton lbToKilo = (RadioButton) startActivity(new
findViewById(R.id.radLbToKilo); Intent(firstActivityname.this,secondactivityname.cl
ass));
− To initialize and reference the RadioButton class for the }
second radio button with the Id name of radKiloToLb, type If the activity that you want to invoke is defined within the
final RadioButton kiloToLb = (RadioButton)
same project, you can rewrite the preceding statement like
findViewById(R.id.radKiloToLb);.
− To code the button, type this:
Button convert = (Button) startActivity(new Intent(this,
findViewById(R.id.btnConvert); SecondActivity.class));
− Set the onclick listener using the appropriate steps. Inside However, this approach is applicable only when the activity

onClick listener type: you want to display is within the same project as the current
weightEntered=Double.parseDouble(weight.getText().t activity.
oString());
if (lbsToKilo.isChecked()){ Binding Activity Data
if (weightEntered <=500){ Two activites were created. The first activity has two edit
convertedWeight = weightEntered /
conversionRate; texts for entering username and password and a button for
result.setText(convertedWeight+ “
opening the second activity and sending the username and
kilograms”);.
} password to it.
else {
Toast.makeText(Main.this,"Pounds must be less than the second activity has a button which when clicked should
500", Toast.LENGTH_LONG).show(); display the username from the first activity in a TextView
} In your main.java class
} Use the putExtra() in your intent.
if (lbsToKilo.isChecked()){ Declare the variables that will hold the input e.g
if (weightEntered <=500){ String name,password
convertedWeight = weightEntered / Final EditText
conversionRate; val1=(EditText)findViewById(R.id.name);
result.setText(convertedWeight+ “ Final EditText
kilograms”);. val2=(EditText)findViewById(R.id.password);
} name=val1.getText().toString();
else { password=val2.getText().toString();
Toast.makeText(Main.this,"Pounds must be less than Put this in the onClick method of the button
500", Toast.LENGTH_LONG).show(); startActivity(new Intent(Main.this,
} second.class).putExtra(“com.example.Adam ", name));
} OR
isChecked( ) method is used to determine if the RadioButton startActivity(new Intent(Main.this,
second.class).putExtra(“com.example.Adam ",
object has been selected name).putExtra(“com.example.Pass”,password));
Linking Activities using Intents
NB: The stringName serves as the key or a reference for the
An Android application can contain one or more activities.
value.
When your application has more than one activity, you often
The stringName must be preceeded by your package name
need to navigate from one to another.
e.g. com.example.stringName.
In Android, you navigate between activities through what is
The value can be a fixed value or user defined value.
known as an intent.
In the other class, use the following code whenever you need
Creating a new Activity
the sent data
Begin by displaying the Project tool window using the Alt-1
keyboard shortcut. getIntent().getStringExtra(“com.example.Adam”);

Page 10 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


// Create an ArrayAdapter using the string array
List Views and a default spinner layout
List views are views that enable you to display a long list of ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this,
items. R.array.planets_array,
In Android, there are two types of list views: ListView and android.R.layout.simple_spinner_item);

SpinnerView. // Specify the layout to use when the list of


ListView view in a vertically scrolling list While the choices appears
adapter.setDropDownViewResource(android.R.layout.si
SpinnerView displays one item at a time from a list and mple_spinner_dropdown_item);
// Apply the adapter to the spinner
enables users to choose among them
spinner.setAdapter(adapter);
Spinner View Coding Spinner Control
The SpinnerView displays one item at a time from a list and A variable should be declared as String to hold the option
enables users to choose among them selected by the user. E.g String levelChoice
The string items that are displayed in the Spinner control After the user selects an option from the Spinner control, the
cannot be typed directly in the Properties pane, but instead selected option is assigned to the declared string variable
are created in a values string using GetSelectedItem( ). The GetSelectedItem( )
array in the res/values folder. method returns the text label of the currently selected
A prompt, which can be used Spinner item.
to display instructions at the levelChoice = level.getSelectedItem().toString();

top of the Spinner control, Responding to user selection

can also be stored in When the user selects an item from the drop-down, the

strings.xml. Spinner object receives an on-item-selected event.


To define the selection event handler for a spinner,

Adding items to String Array and prompt display in the implement the AdapterView.OnItemSelectedListener

spinner view interface and the corresponding onItemSelected() callback

You can add a spinner to your layout with the Spinner object. method.

You should usually do so in your XML layout with a <Spinner> First you need to specify the interface implementation by

element. For example: calling setOnItemSelectedListener():


<Spinner After referencing the spinner.
android:id="@+id/planets_spinner"
Type spinner.setOnitemSelected(new O choose the first
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> option to automatically generate the code
The choices you provide for the spinner can come from any Spinner spinner = (Spinner)
findViewById(R.id.spinner);
source. It can be provided through a SpinnerAdapter or spinner.setOnItemSelectedListener(new
through the entries attribute in the <spinner> element. OnItemSelectedListener()
{
You can provide the list of items with a string array defined @Override
in a string resource file. public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id){
<string-array name="level“> <item> one </item>
// if an item was selected. You can retrieve
<item>
the selected item using
two</item><item>three</item><item>four</item>item>
// parent.getItemAtPosition(pos)
</string-array>
Switch(pos) {
Adding a Spinner Control with String Array Entries (Using case 0:
Toast.makeText(MainActivity.this,"this is
<spinner>
musa", Toast.LENGTH_LONG).show();
After entering the items in an array, the Spinner property break;
called Entries connects the String Array to the Spinner default:
control for display in the application. Toast.makeText(MainActivity.this,"nothing
has been selected", Toast.LENGTH_LONG).show();
You can also add another string in the string resource to break;
display the default message when the spinner is launched. }
@Override
It is displayed using the prompt property. public void onNothingSelected(AdapterView<?>
In main.xml, add <spinner/>. Give it an id parent{ }
});
Add the property android:entries=“@arrays/name of the
ListView Control
previously created string array” and another property
The list View always extends the ListActivity class
android:prompt=“@string/name of prompt”
Adding a Spinner Control with String Array Entries (Using It displays a list of items by binding to a data source

SpinnerAdapter in the onCreate() method, you don’t need to call the

you can use the following code in your Activity to supply the setContentView() method to load the UI from the xml file

spinner with the array using an instance of ArrayAdapter because the ListActivity class already includes the ListView.
Spinner spinner = (Spinner)
findViewById(R.id.spinner);

Page 11 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


In the onCreate() method, you use the setListAdapter() In Main.java, press the Enter key after the closing brace of
method to programmatically fill the entire screen of the the onCreate method to insert a new line. To respond to the
activity with a ListView. The ArrayAdapter object manages user’s selection, type
the array of strings that will be displayed by the ListView protected void onListItemClick(ListView l, View v,
int position, long id).
The onListItemClick() method is fired whenever an item
Type an opening brace after the statement and press the
in the ListView has been clicked Enter key.
Declaring the array Decision Structure
Before the items in a list can be displayed, the string of items
Each item in the list produces a different result when selected,
must be declared. The Switch statement allows you to choose from many
By using an array variable, which can store more than one statements based on an integer or char (single character)
value, you can avoid assigning a separate variable for each
input.
item in the list. switch(position){
Each individual item in an array that contains a value is called case 0:
an element. startActivity(new
You can declare an array containing numeric values as in the break;
following coding example: double[ ] weather={72.3, case 1:
65.0}; /startActivt
Declare a String array containing text values using following break;
code: default:
String[] names={“Musa", “Sani",“Isa", “sadiq"};
//statements that are executed if position != any of the
This is done immediately after the
cases
super.onCreate(savedInstanceState); statement in
}
Main.java
Within the braces of the onListItemClick method, type the
The setListAdapter and Array Adapter
code above
An adapter provides a data model for the layout of the list
and for converting the data from the array into list items.
Create an activity MainActivity
The ListView and adapter work together to display a list.
Your activity should extend ListActivity
setListAdapter projects your data to the onscreen list on your
Immediately after super.onCreate decalre your array
device by connecting the ListActivity’s ListView object to the
String [] names={“boy”,”girl”};
array data. Immediately after the declaration,
It contains the information to connect the onscreen list with setListAdapter(new ArrayAdapter<String>(this,
android.R.layout. simple_list_item_1, names));
the names array.
After the onCreate Method add
Calling it binds the elements of the array to a ListView layout.
protected void onListItemClick(ListView l, View v,
a ListAdapter called an ArrayAdapter<String> i supplies the int position, long id){
switch (position){
String array data to the ListView. case 0: break;
The three parameters that follow ArrayAdapter refer to the case 1: break;
}
this class, a generic layout called simple_list_item_1, and the }
array named names. AutoCompleteTextView View
After initializing the String array, press the Enter key, type The AutoCompleteTextView is a view that is similar to
setListAdapter(new ArrayAdapter<String>(this,
EditText (a subclass of EditText), except that it shows a list
android.R.layout. simple_list_item_1, names));,
and then press the Enter key. Point toArrayAdapter and of completion suggestions automatically while the user is

click Import ‘ArrayAdapter’ (android.widget). typing.

Using onListItemClick Method Programming the autocomplete view requires the creation of

Each of the names displayed in the list can be selected by a string array
String [] names={“habu”,”peter”};
tapping the name on the mobile device.
The ArrayAdapter object manages the array of strings that
The method onListItemClick( ) is called when an item in
will be displayed by the AutoCompleteTextView.
the list is selected. ArrayAdapter<String> adapter = new
When a name in the list is selected, the position of the item ArrayAdapter<String>(this,android.R.layout.simple_d
ropdown_item_1line, presidents);
is passed from the onListItemClick and evaluated with a
The setThreshold() method sets the minimum number of
decision structure. If the user selects the first attraction, the
characters the user must type before the suggestions appear
position parameter is assigned an integer value of 0. The
as a drop-down menu:
second item is assigned the position of 1, and so forth. textView.setThreshold(3);

Page 12 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba


The list of suggestions to display for the
AutoCompleteTextView is obtained from the ArrayAdapter
object:
textView.setAdapter(adapter);
Date and Time Picker View
The TimePicker displays a standard UI to enable users to set
a time.
We use the <TimePicker> By default, it displays the time in
the AM/PM format. If you wish to display the time in the
24-hour format, you can use the setIs24HourView()
method.
To programmatically get the time set by the user, use the
getHour() and getCurrentMinute() methods
Using the DatePicker, you can also enable users to select a
particular date on the activity.
you call the getMonth(), getDayOfMonth(), and getYear()
methods to get the month, day, and year, respectively

Page 13 of 13 CSC4211 Advances in Mobile Technology 2018/2019 ISG Mairoba

You might also like