Activities:

  • Are containers for views they have a short lifespan while on the screen
  • have a defined lifecycle OnCreate, Onstart, On Pause, On Resume? OnStop, OnDestroy
  • Activities live on the stack - when we navigate to a new activity thee last one is stoered onthe stack till the user goes back
  • Activities can launch others to get a result (e.g. edit list item) use startActivityForResult()

Services

  • Service can have a longer lifespan as long as it has resources - they run in the background though so can be accessed across different activities
  • Similar lifecycle to Activities: OnCreate, Onstart, OnStop, OnDestroy
  • will be killed of if not in used for a while.

Intents

  • Method of passing data beetween different objects (Activities, Services, Widgets, Notifications, ....) they come to/form your app elements and from the system too.
  • Intent has an ACTION which is the action for it, there are standard actions in the Manifest file
  • Intent has DATA which can be a String (e.g. url)
  • can also have extra data which is troed in a bundle

Android manifest file (AndroidManifest.xml)

  • Declare the activities and services you use
  • for each of these activities you can declare intent filters which can receive Intents from anywhere
  • Example: this intent filter receives intents for url file:///.opml file i.e. my activity can handle and opml file.
<activity android:name="FeedSelectorActivity" android:configChanges="orientation" > 
	<intent-filter>
		<action android:name="android.intent.action.VIEW" />
		<category android:name="android.intent.category.BROWSABLE" />
		<category android:name="android.intent.category.DEFAULT" />
		<data android:scheme="file" android:mimeType="*/*" android:host="*" android:pathPattern=".*\\.opml"/>
		<data android:scheme="file" android:mimeType="*/*" android:host="*" android:pathPattern=".*\\.xml"/> 
		<data android:scheme="file" android:mimeType="*/*" android:host="*" android:pathPattern=".*\\.txt"/>
	</intent-filter>
</activity>

Broadcast Intents

  • Other pieces of software (or the system) can throw BroadcastIntents then the intent filters you declare can capture them.
  • This allows the interaction of many seperate smaller pieces of software.

This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 1.6.1.13621 - Documentation