According to the Android docs Intent extra name must have a package prefix. I've been using Intent extra names without prefixes for a long time and it seems like there is no chance of collision since what really matters is the Intent action being unique. So are the docs just wrong or am I missing something?
The docs for putExtra say:
Add extended data to the intent. The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".
Intents are used to signal to the Android system that a certain event has occurred. Intents often describe the action which should be performed and provide data upon which such an action should be done. For example, your application can start a browser component for a certain URL via an intent.
android. intent. action. MAIN means that this activity is the entry point of the application, i.e. when you launch the application, this activity is created.
We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.
Use Intent Flags Intents are used to launch activities on Android. You can set flags that control the task that will contain the activity. Flags exist to create a new activity, use an existing activity, or bring an existing instance of an activity to the front.
I believe the Android docs recommend using fully-qualified extras is to handle an uncommon edge case. The edge case is when you are:
AND
Phew, it all sounds very unlikely. If you aren't handling public Intent actions then it still seems as though there is no need to fully-qualify your extras, but I guess it doesn't hurt to do it all the time if you are the paranoid type.
Intents can be passed on to other apps and the system it self, so courtesy is to use a package namespace.
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