I have just started with android. while going through code on GitHub, for sending a broadcast, I came across
addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
I am unable to understand the functionality of the above statement..if someone could help, it would be really nice. Regards
ACTION_VIEW is the action on Intent. public static final String ACTION_VIEW. Since: API Level 1 Activity Action: Display the data to the user. This is the most common action performed on data -- it is the generic action you can use on a piece of data to get the most reasonable thing to occur.
An Intent object carries information that the Android system uses to determine which component to start (such as the exact component name or component category that should receive the intent), plus information that the recipient component uses in order to properly perform the action (such as the action to take and the ...
flag — FLAG_ACTIVITY_CLEAR_TASK: This clears any existing task that would be associated with the Activity before the Activity is started. This Activity then becomes the new root of the task and old Activities are finished.
In 1. case we deliver the notification. In 2. case we don't (should not). Note that the system adds FLAG_EXCLUDE_STOPPED_PACKAGES to all broadcast intents. It does this to prevent broadcasts from background services from inadvertently or unnecessarily launching components of stoppped applications.
You would normally use that flag if the application that receives the intent has never been started. Here is an example. Show activity on this post.
Applications are in a stopped state when they are first installed but are not yet launched and when they are manually stopped by the user (in Manage Applications). We do not add the FLAG_INCLUDE_STOPPED_PACKAGES flag since we are not sure why the app has been stopped.
However, when app is resumed again all pending notifications are delivered. This happens even when phone is awake and not sleeping. This is not ideal for me as I am trying to develop a calling app.
You would normally use that flag if the application that receives the intent has never been started.
Here is an example.
Intent intent = new Intent("my.action.Intent");
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(intent);
When you install an app on your device it is in "stopped" state, so the app component (activities, receivers etc.) will not respond to intents unless you either first time launch the app (to exist "stopped" state ) or add the FLAG_INCLUDE_STOPPED_PACKAGES flag.
From the API guide:
Developers Guide
"If set, this intent will always match any components in packages that are currently stopped."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With