Android intent's resolveActivity and Package Manager

纵饮孤独 提交于 2019-12-11 04:10:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!