PPT

stuckwarmersMobile - Wireless

Dec 14, 2013 (4 years and 17 days ago)

233 views

CSE2102 Introduction to
Software Engineering

Lab 2

Sept/4/2013

Today

1.
App Fundamentals and Skeleton (last week)

1.
Architecture Diagram (today)

2.
Activity (today)

1.
Function

2.
Lifecycle

3.
Coding Assignment

3.
Services (today)

1.
Function

2.
Lifecycle

3.
Coding
Assignment

4.
Content Providers (week 37/3)

5.
Intent and Intent Filters (
week
38/4)

6.
Processes and Threads
(week
39/5)

7.
Permission
(week
40/6)

8.
App Widgets
(week
40/6)

9.
Android Manifests
(week
40/6)

Architecture Diagram

http://developer.android.com/images/system
-
architecture.jpg

What are the functions of an
activity
?

1.
Interact in most case with
user

2.
Usually applications have several activities

3.
Each is implemented as a
subclass

of base Activity class

4.
Creates the window to place
UI

1.
setContentView
(
R.layout.home_activity
);

5.
Methods






1.
protected
void
onCreate
(Bundle
savedInstanceState
);
// initialize

2.
protected
void
onStart
();
//activity visible

3.
protected
void
onRestart
();
//before activity becomes visible

4.
protected
void
onResume
();
// activity visible after being paused

5.
protected
void
onPause
();
// another activity becomes visible

6.
protected
void
onStop
();
// activity not visible

7.
protected
void
onDestroy
();
// cleanup and destroy activity

What is the lifecycle of an
activity
?

Coding Assignment (5 min)

1.
Start Android Developer Tools

2.
Create a new Project with one Activity

3.
Define all six methods in that activity

What are the functions of a
service
?

1.
Runs in the background


what does it mean?

2.
Each is implemented as a
subclass

of base
Service
class

3.
Examples


Music, TCP, REST, and other long running
operations…

4.
Methods

1.
public void
onCreate
()
// initialize

2.
public
void

onStartCommand
()
// started

3.
public
void
onBind
()

// activity to service communication

4.
public
void

onDestroy
()
// cleanup resources

5.
public
void

stopService
()
// stop service

Service
-

Function


Services must be
declared

in AndroidManifest.xml


<service


android:name=“path.to.MyAppService"

android:label="@string/service_name">
</service>

Remember to update the string resource file!

What is the service lifecycle?

1.
Does a Service have Lifecycle?

1.
Arguably no, since there is no interaction with
the user, internally yes.

2.
Who can start a service?

1.
Services, Receivers, and Activities

3.
How do you start a service?


Intent
i
=
new

Intent(
getApplicationContext
,
MyAppService.
class
);


i.putExtra
(“key", “value");


getApplicationContext.startService
(
i
);



Coding Assignment (5 min)


Create a Service class


Add 5 methods


Start that Service through the Activity and
pass a key/value pair


Print out value/pair using activity on console

Questions



What are the four layers of the Android Architecture
Stack?


What is the function of an activity?


What are the four states of an activity?


What are the six methods that change the state of an
activity?


What is a Service?


What are the 5 methods that implement a service?


What is the difference between Activity and Service?


Who can start service?


References


http://developer.android.com/guide/compone
nts/activities.html


http://developer.android.com/guide/compone
nts/services.html


Professional Android 4 Application
Development

(Reto Meier, 2012)