Android intent's resolveActivity and Package Manager
Asked Answered
R

1

2

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?

Rodney answered 19/6, 2017 at 1:6 Comment(1)
There is no obvious reason why it is like this. Perhaps only the Google developer that wrote the function could answer.Gann
E
2

Package Manager is like a registry. it contains all details of application as given belowenter image description here

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.

Externality answered 6/5, 2018 at 13:1 Comment(1)
This doesn't answer the question of why the parameter is neededGann

© 2022 - 2024 — McMap. All rights reserved.