Skip to content

Instantly share code, notes, and snippets.

@logkcal
Created February 15, 2012 01:14
Show Gist options
  • Save logkcal/1832264 to your computer and use it in GitHub Desktop.
Save logkcal/1832264 to your computer and use it in GitHub Desktop.
android framework & design guidelines
  • 3 of core application components are activated through messages called intents. an abstraction of an operation to be performed, or something that has happened and is being announced. intent object contains a component, an action, and so forth.
  • begins a new task, when an activity is started.
  • brings an existing instance of the activity forward.
  • clears all activities except the root one when a task goes into the background.
Launch Mode
  • standard (the default) -- the activity can be instantiated multiple times on one or more tasks.
  • singleTop / FLAG_ACTIVITY_SINGLE_TOP -- no more than one instance of the activity on a task stack.
  • singleTask / FLAG_ACTIVITY_NEW_TASK -- no more than one instance throughout the Android system.
  • singleInstance -- this activity is the one and only activity in tasks.
  • FLAG_ACTIVITY_CLEAR_TOP -- destroys other activities on top of this activity on the current task.
  • FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_NEW_TASK -- locates an existing activity in another task and puts it into a position where it can respond to the intent.

A service can essentially take two forms:

  • Started -- when an application component such as an activity starts it by calling startService(). The service should stop itself, when the operation is done.
  • Bound -- when an application component binds to it by calling bindService(). Multiple components can bind to the serivce at once, but when all of them unbind, the service is destroyed.
  • But, it's simply a matter of whether you implement a couple callback methods: onStartCommand() to allow components to start it and onBind() to allow binding.

Caution: A services runs in the same process as the application in which it is declared and in the main thread of that application, by default. So, if your service performs intensive or blocking operations while the user interacts with an activity from the same application, the service will slow down activity performance. To avoid impacting application performance, you should start a new thread inside the service.

service_lifecycle.png

  • a service should either be used locally by an intent that explicitly names the service class, or an intent filter.
  • a start continuation flag that onStartCommand method returns specifies how to continue a service if it is killed.
  • a foreground service must provide a notification for the status bar, which is placed under the "Ongoing" heading, which means that the notification cannot be dismissed unless the service is either stopped or removed from the foreground.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment