4.
Activity
• Activity is usually a single screen
– Implemented as a single class extending Activity
– Displays user interface controls (views)
– Reacts on user input / events
• An application typically consists of
several screens
– Each screen is implemented by
one activity
– Moving to the next screen means
starting a new activity
– An activity may return a result to
the previous activity
(C) Hochschule für Technik
Fachhochschule Nordwestschweiz
3 December 2008 4

7.
Android Component Model
• Component Software
– Activities can reuse functionality from other
components simply by making a request
in form of an Intent
– Activities can be replaced at any time
by a new Activity with an equivalent
Intent Filter
Intent i = new Intent(
"com.google.android.radar.SHOW_RADAR");
i.putExtra("latitude", 47.6f);
i.putExtra("longitude", 8.23f);
startActivity(i);
(C) Hochschule für Technik
Fachhochschule Nordwestschweiz
3 December 2008 7

12.
Activity Life Cycle (1/2)
• onCreate
– Called when activity is first created (with null parameter) or when activity
was killed (called with a bundle)
– Initialization of views
• onRestart
– Called when activity was stopped only
• onStart
– Activity becomes visible to user, animations could be started
• onRestoreInstanceState
– Restore view state
• onResume
– New activity is visible, TOS, camera might be used here
(C) Hochschule für Technik
Fachhochschule Nordwestschweiz
3 December 2008 12

13.
Activity Life Cycle (2/2)
• onSaveInstanceState
– Save UI state of a complex dialog
=> onCreate
=> onRestoreInstanceState
– If application is explicitly finished, this method is not called
– Called before or after onPause
• onPause
– Activity no longer TOS
– New activity is not started until onPause returns
• onStop
– Activity no longer visible
• onDestroy
– Release resources; it is not guaranteed that this method is called
(C) Hochschule für Technik
Fachhochschule Nordwestschweiz
3 December 2008 13

18.
Process / Thread
• Inactive Activities
– If an activity does not consume events,
the system assumes that the activity
has a problem
(C) Hochschule für Technik
Fachhochschule Nordwestschweiz
3 December 2008 18

22.
Service
• Characteristics
– Execution of long running tasks and business logic outside an activity
E.g. a background task that has to download data periodically
– Services can explicitly be started and stopped
– Communication with service
In-process if service runs in same APK
Inter-Process Communication across APKs (AIDL)
(C) Hochschule für Technik
Fachhochschule Nordwestschweiz
3 December 2008 22