Activity
application
presentation layer
single, focused things
that user can do
rough synonym of
“screen”
Slide 5
Slide 5 text
src/**/MainActivity.java
public class MainActivity extends Activity {
!
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Slide 6
Slide 6 text
AndroidManifest.xml
Slide 7
Slide 7 text
Activity Stack
Slide 8
Slide 8 text
Activity
ActionBar
Slide 9
Slide 9 text
supports consistent
navigation and view switching
(tabs or drop-down lists)
http://developer.android.com/guide/topics/ui/actionbar.html
ActionBar
dedicated space for app
identity and user's location
makes important actions
accessible (such as Search)
Slide 10
Slide 10 text
An action bar that includes
the [1] app icon, [2] two action
items, and [3] action overflow.
Slide 11
Slide 11 text
Activity
ActionBar
Views
Slide 12
Slide 12 text
View is
java class
a visual application component on a screen
http://developer.android.com/reference/android/view/View.html
onMeasure()
onLayout()
onDraw()
with methods:
Slide 13
Slide 13 text
View
Slide 14
Slide 14 text
View
TextView
ImageView Button
Slide 15
Slide 15 text
Example
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
TextView view = new TextView(this);
view.setText("Hello World");
setContentView(view);
}
Slide 16
Slide 16 text
Example
@Override
protected void
TextView view =
view.setText(
}
What’s this?
this
Slide 17
Slide 17 text
Example
@Override
protected void
TextView view =
view.setText(
}
this
Context
Slide 18
Slide 18 text
Context
access to application-specific
resources and classes
for launching activities,
broadcasting and receiving
intents, etc.
access to up-calls for
application-level operations
Slide 19
Slide 19 text
Example
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
mapView = new MapView(this);
mapView.onCreate(state);
setContentView(mapView);
}
Slide 20
Slide 20 text
Example
@Override
protected void
mapView = new MapView(
setContentView(mapV
}
Context
this
in Activity
Layout resource from res/
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
setContentView(R.layout.main);
}
Slide 29
Slide 29 text
@Override
protected void onCreate(Bundle state) {
super.onCreate(state);
View view = LayoutInflater.from(this)
.inflate(R.layout.main, null);
setContentView(view);
}
same as
Slide 30
Slide 30 text
LayoutInflater
1. fill (a balloon, tyre, or other expandable
structure) with air or gas so that it
becomes distended.
2. increase (something) by a large or
excessive amount.
View view = LayoutInflater.from(this)
.inflate(R.layout.activity_main, null);
inflate!
/ɪnˈfleɪt/!
verb
Slide 31
Slide 31 text
LayoutInflater
1. fill (a balloon, tyre, or other expandable
structure) with air or gas so that it
becomes distended.
2. increase (something) by a large or
excessive amount.
View view = LayoutInflater.from(this)
.inflate(R.layout.activity_main, null);
inflate!
/ɪnˈfleɪt/!
verb
Fill View from XML
Configuration
qualifiers
en, fr, en-rUS, fr-rFR, fr-rCA
Language and region
mcc310, mcc310-mnc004
Mobile country code
Screen size small, normal, large, xlarge
Orientation land, port
Screen density ldpi, mdpi, hdpi, nodpi
Slide 55
Slide 55 text
Stored within res/values
Simple values
Strings
Colors
Dimensions
Styles
String or integer arrays
Slide 56
Slide 56 text
Do not use hard-coded values in
your application code (num, strings)
Use wrap_content, fill_parent, or the
dp unit for layout dimensions
Test Your Application on Multiple
Screens
!