Mobile APP Development Training Slides
Mobile APP Development Training Slides
Training
1
Outline
Introduction to Mobile Application
Development
Mobile Application Tools
Android System Overview
Getting Started With Android Studio IDE
2
What is Mobile Application
Development?
5
Introduction to Android
What is Android
Android is an operating system for mobile devices such
as smartphones and tablet computers. It is developed by the Open
Handset Alliance led by Google.
Android has beaten Apple iOS, being the leading mobile operating
system from first quarter of 2011
6
TOP U.S SMARTPHONE OS
SHARE
Popular mobile
device OS: 52% of
U.S. smartphone
market
Developed by Open
Handset Alliance,
led by Google
Google claims
900,000 Android
device activations
7
Android Architecture
Android System Overview
10
List Preference: ListPreference is used to display the list of entries as a dialog from
which a user can choose a single selection. This displays a group of radio buttons as
shown in figure among which only one button can be selected.
Edit Text Preference: This opens up the dialog box where user can
enter a value as shown in the figure. When text is typed into the field,
it returns a string value
12
GETTING STARTED WITH ANDROID
STUDIO
15
Getting Started (1)
Need to install Java Development Kit (JDK) to
write
Java (and Android) programs
Do not install Java Runtime Environment (JRE);
JDK and JRE are different!
Can download the JDK for your OS at
http://java.oracle.com
Alternatively, for OS X, Linux:
OS X:
Open /Applications/Utilities/Terminal.app
Type javac at command line
Install Java when prompt appears
Linux:
Type sudo apt–get install default–jdk at command line
(Debian, Ubuntu)
Other distributions: consult distribution’s documentation
16
Install!
17
Getting Started (2)
After installing JDK, download Android SDK from
http://developer.android.com
Simplest: download and install Android Studio bundle
(including Android SDK) for your OS
Alternatives:
Download/install Android Developer Tools from this site
(based on Eclipse)
Install Android SDK tools by themselves, then install ADT
for Eclipse separately (from this site)
We’ll use Android Studio with SDK included (easy)
18
Install!
19
Getting Started (3)
Install Android Studio directly (Windows, Mac); unzip to directory
android-studio, then run ./android-studio/bin/studio.sh (Linux)
20
Getting Started (4)
Strongly recommend
testing with real
Android device
Android emulator: very Settings
slow
Faster emulator:
Genymotion
Install USB drivers for
your Android device!
Bring up the Android
SDK Manager
Recommended: Install
Android 2.2, 2.3.3 APIs
and 4.x API
Do not worry about Intel Now you’re ready for Android development!
21 x86 Atom, MIPS system
images
Outline
Introduction to Android
Getting Started
Android Programming
22
Android Highlights (1)
Android apps execute
on Dalvik VM, a “clean-
room” implementation
of JVM
Dalvik optimized for
efficient execution
Dalvik: register-based
VM, unlike Oracle’s stack-
based JVM
Java .class bytecode
translated to Dalvik
EXecutable (DEX)
bytecode, which Dalvik
24
interprets
Android Highlights (2)
Android apps written in Java 5
Actually, a Java dialect (Apache Harmony)
Everything we’ve learned still holds
Apps use four main components:
Activity: A “single screen” that’s visible to user
Service: Long-running background “part” of app
(not separate process or thread)
ContentProvider: Manages app data (usually
stored in database) and data access for queries
BroadcastReceiver: Component that listens for
particular Android system “events”, e.g., “found
wireless device”, and responds accordingly
25
App Manifest
Every Android app must include an Android Manifest.xml
file describing functionality
The manifest specifies:
App’s Activities, Services, etc.
Permissions requested by app
Minimum API required
Hardware features required, e.g., camera with autofocus
External libraries to which app is linked, e.g., Google Maps
library
26
Activity Lifecycle
Activity: key building
block of Android apps
Extend Activity class,
override on Create(),
on Pause(), on
Resume() methods
Dalvik VM can stop any
Activity without
warning, so saving state
is important!
Activities need to be
“responsive”, otherwise
Android shows user “App
Not Responsive” warning:
Place lengthy operations in
Runnable Threads,
27 AsyncTasks
28
App Creation Checklist
If you own an Android device:
Ensure drivers are installed
Enable developer options on device under Settings,
specifically USB Debugging
Android 4.2+: Go to Settings→About phone, press Build number
7 times to enable developer options
For Android Studio:
Under File→Settings→Appearance, enable “Show tool
window bars”; the Android view shows LogCat,
devices
Programs should log states via android.util.Log’s
Log.d(APP_TAG_STR, “debug”), where APP_TAG_STR is a
final String tag denoting your app
Other commands: Log.e() (error); Log.i() (info); Log.w()
29 (warning); Log.v() (verbose) – same parameters
Creating Android App (1)
Creating Android app project in Android
Studio:
Go to File→New Project
Enter app, project name
Choose package name using “reverse URL” notation,
e.g., edu.osu.myapp
Select APIs for app, then click Next
30
Creating Android App (2)
31
Creating Android App (3)
Determine what
kind of Activity to
create; then click
Next
We’ll choose a
Blank Activity for
simplicity
Enter information
about your Activity,
then click Finish
This creates a
“Hello World” app
32
Deploying the App
Two choices for deployment:
Real Android device
Android virtual device
Plug in your real device;
otherwise, create an Android
virtual device
Emulator is slow. Try Intel
accelerated version, or
perhaps
http://www.genymotion.
com/
Run the app: press “Run”
button in toolbar
33
Underlying Source Code
package edu.osu.helloandroid;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity
{
@Override
protected void on Create(Bundle saved Instance State)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); }
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if
it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
34
Underlying GUI Code
res/layout/activity_main.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
35
The App Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="edu.osu.helloandroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
36
android:name="edu.osu.helloandroid.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
37
A More Interesting
App(Example)
We’ll now examine
an app with more
features: WiFi
Tester (code on
class website)
Press a button,
scan for WiFi
access points
(APs), display them
38
Underlying Source Code (1)
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wi_fi);
// Set up WifiManager.
mWifiManager = (WifiManager)
getSystemService(Context.WIFI_SERVICE);
mIntentFilter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
}
40
Underlying Source Code (2)
@Override
Code much more complex protected void onResume()
First get system Wifi Manager {
super.onResume();
Create listener Object for
button that performs scans registerReceiver(mReceiver,
mIntentFilter);
We register Broadcast }
Receiver, m Receiver, to listen
for Wifi Manager’s “finished @Override
scan” system event (expressed protected void onPause()
as Intent Wifi {
super.onPause();
Manager.SCAN_RESULTS_
unregisterReceiver(mReceiver
AVAILABLE_ACTION) );
Unregister Broadcast Receiver }
when leaving Activity
41
The Broadcast Receiver
private final BroadcastReceiver mReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if
(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION.equals(action))
{
Log.e(TAG, "Scan results available");
List<ScanResult> scanResults =
mWifiManager.getScanResults();
mApStr = "";
42
for (ScanResult result : scanResults)
{
mApStr = mApStr + result.SSID + ";
";
mApStr = mApStr + result.BSSID +
"; ";
mApStr = mApStr +
result.capabilities + "; ";
mApStr = mApStr + result.frequency
+ " MHz;";
mApStr = mApStr + result.level + "
dBm\n\n";
}
// Update UI to show all this
information.
setTextView(mApStr);
}
}
};
43
User Interface
private void set Text View(String
str)
{
Text View tv = (Text View)
find View ById(R.id.text view);
tv.set Movement Method(new
Scrolling Movement Method());
tv.setText(str);
}
46
Android User Interface -2
47
Create a Linear Layout -1
In Android Studio's Project window, open app > res >
layout > activity_main.xml.This XML file defines the
layout of your activity. It contains the default "Hello
World" text view.
When you open a layout file, you’re first shown the
design editor in the Layout Editor. For this lesson, you
work directly with the XML, so click the Text tab at
the bottom of the window to switch to the text editor.
Delete everything and insert the following XML:
48
Create a Linear Layout-2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/r
es/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
49
Add a Text Field
<LinearLayout
xmlns:android="http://schmas.android.com/apk/res/a
ndroid"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
</LinearLayout>
50
Add Button
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="@+id/edit_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send" />
</LinearLayout>
51
Make the Input Box Fill in the Screen Width
In activity_main.xml, modify the <
Edit Text> so that the attributes look like
this:
<Edit Text
android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message"
/>
52
COMPLETE UI EXAMPLE
Here’s how your complete activity_main.xmllayout file should
now look:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/androi
d"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
53
android:text="@string/button_send" />
</LinearLayout>
Android Studio practice
54
Android Studio practice
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1"
android:layout_marginLeft="10pt"
android:layout_marginRight="10pt"
android:layout_marginTop="3pt">
<EditText
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginRight="5pt"
android:id="@+id/etNum1"
android:layout_width="match_parent“
android:inputType="numberDecimal">
55 </EditText>
<EditText
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="5pt"
android:id="@+id/etNum2"
android:layout_width="match_parent"
android:inputType="numberDecimal">
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2"
android:layout_marginTop="3pt"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt">
<Button android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="+“ android:textSize="8pt"
56
android:id="@+id/btnAdd">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="-"
android:textSize="8pt"
android:id="@+id/btnSub">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="*"
android:textSize="8pt"
android:id="@+id/btnMult">
</Button>
57
<Button
android:layout_height="wrap_conten
t"
android:layout_width="match_parent
"
android:layout_weight="1"
android:text="/"
android:textSize="8pt"
android:id="@+id/btnDiv">
</Button>
</LinearLayout>
<TextView
android:layout_height="wrap_content
"
android:layout_width="match_parent"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt"
android:textSize="12pt"
android:layout_marginTop="3pt"
android:id="@+id/tvResult"
android:gravity="center_horizontal"
>
58
</TextView>
public class MainActivity extends Activity implements
OnClickListener {
EditText etNum1;
EditText etNum2;
Button btnAdd;
Button btnSub;
Button btnMult;
Button btnDiv;
TextView tvResult;
String oper = "";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// set a listener
btnAdd.setOnClickListener(this);
btnSub.setOnClickListener(this);
btnMult.setOnClickListener(this);
btnDiv.setOnClickListener(this);
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
float num1 = 0;
float num2 = 0;
float result = 0;
60
// read EditText and fill variables with numbers
num1 = Float.parseFloat(etNum1.getText().toString());
num2 = Float.parseFloat(etNum2.getText().toString());
// defines the button that has been clicked and performs the operation
// write operation into oper, we will use it later for output
switch (v.getId()) {
case R.id.btnAdd:
oper = "+";
result = num1 + num2;
break;
case R.id.btnSub:
oper = "-";
result = num1 - num2;
break;
case R.id.btnMult:
oper = "*";
result = num1 * num2;
break;
case R.id.btnDiv:
oper = "/";
result = num1 / num2;
break;
default:
break;
}
// form the output line
tvResult.setText(num1 + " " + oper + " " + num2 + " = " + result);
}
61 }
OUTPUT
62
How to Start Mobile Application
Business
63
The Android Market or the
Android central is known to be the
very own repository of Google for
Android applications.
64
Android Market recently renamed as
Google play is developed and
maintained by Google. It is an online
electronic store or digital application
distribution platform for android
powered devices.
65
The application developed by any
developer has to be tested before
it is uploaded to the Android
market to ensure that your app is
error and bug free.
66
The developer needs to register
before publishing the app with a
publisher account by visiting the
Google Play Developer console at
https://play.google.com/apps/
publish/.
67
TOOLS & MATERIALS NEEDED
FOR THE DEVELOPMENT
THIS MATERIAL
VIDEO TUTORIALS (ONLINE & OFFLINE)
INTERNET
GOOD BOOK (BEGINNER LEVEL IN MOBILE APP
DEVELOPMENT)
HIGH CONFIGURATION LAPTOP WITH AT LEAST
4GB RAM
ETC.
68