问题
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
回答1:
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);
回答2:
From the API guide:
Developers Guide
"If set, this intent will always match any components in packages that are currently stopped."
回答3:
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.
来源:https://stackoverflow.com/questions/43546453/flag-include-stopped-packages