问题
To check if an intent can be handled, you would call:
if (intent.resolveActivity(getPackageManager()) != null) {
// start activity
}
Question - why is the parameter to package manager needed if the same getPackageManager() is always passed? Are there cases where different package manager may be passed?
回答1:
Package Manager is like a registry. it contains all details of application as given below
that's why you are providing package manager args to resolve intent before the fire. alternatively, you can also use chooser before firing intent.in other cases, you may want to retrieve different application info, then you can use a package manager. There is no obvious reason why we have to pass the argument. Perhaps only the Google developer that wrote the function could answer.
来源:https://stackoverflow.com/questions/44620981/android-intents-resolveactivity-and-package-manager