From the Pro Android 2 book: "ComponentName wraps a package name and a class name together. For example..."
Intent intent = new Intent();
Intent.setCompnonet(new ComponentName(
"com.android.contacts"
,"com.android.contacts.DialContactsEntryActivity");
startActivity(intent)
If you look at the example, you'll notice that the package name can be easily derived from the class name. So the obvious question is: why two parameters? Why not provide only the class name?
Is there a scenario where the class passed to the ComponentName constructor doesn't belong to the package passed to the same constructor?
Create a new component identifier from a Context and Class object. Context : A Context for the package implementing the component, from which the actual package name will be retrieved. This value cannot be null .
Each component has a label on it which can be changed for another one. As you may have many components in your graph and they may have some specified functions, you can give them names according to what they do. Otherwise you would have many different components with identical names in your graph.
The application component may exist within an application whose package name (declared in its Android manifest) is completely different from the Java package for the particular class that defines the component. An example is the MapsActivity in the Google Maps application:
intent.setComponent(new ComponentName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity"));
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