Skip to content

Instantly share code, notes, and snippets.

@hetang
Last active April 10, 2018 21:21
Show Gist options
  • Save hetang/c608c18d44f29de172562712725600bf to your computer and use it in GitHub Desktop.
Save hetang/c608c18d44f29de172562712725600bf to your computer and use it in GitHub Desktop.
Context Scope and its capability in Android

Context Capabilities

Application Activity Service ContentProvider BroadcastReceiver
Show a Dialog NO YES NO NO NO
Start an Activity NO1 YES NO1 NO1 NO
Layout Inflation NO2 YES NO2 NO2 NO
Start a Service YES YES YES YES YES
Bind to a Service YES YES YES YES NO
Send a Broadcast YES YES YES YES YES
Register BroadcastReceiver YES YES YES YES NO
Load Resource Values YES YES YES YES YES

  1. An application CAN start an Activity from here, but it requires that a new task be created. This may fit specific use cases, but can create non-standard back stack behaviors in your application and is generally not recommended or considered good practice.
  2. This is legal, but inflation will be done with the default theme for the system on which you are running, not what’s defined in your application.
  3. Allowed if the receiver is null, which is used for obtaining the current value of a sticky broadcast, on Android 4.2 and above.

Original Article

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment