0

I am unsure about the purpose of the resolveActivity method in the Intent class, based on the docs the resolveActivity method "returns the Activity component that should be used to handle this intent"

Since my Intent instance has Intent.ACTION_VIEW as it's parameter, the getAction() is non null and the intent must be handled by the Activity. I don't see the purpose in using actionView.resolveActivity(packageManager).

val actionView = Intent(Intent.ACTION_VIEW, currentUri) //Creation of the Intent Object

actionView.resolveActivity(packageManager)?.run {  //Checking if the resolveActivity instance is null
    ...}
  • You can use it and check for non-null result to know whether it's safe to call `startActivity` with that same intent. Otherwise, I think the actual result has questionable usefulness. There might be multiple possible components that can handle the intent, and so you usually don't want to just use the first one that pops up. That's sort of like clicking "I'm feeling lucky" on google.com. Better to let the user decide if there are multiple choices. – Tenfour04 Oct 25 '22 at 17:23
  • here is more about resolveIntent https://stackoverflow.com/questions/55676934/what-exactly-is-intent-resolveactivitygetpackagemanager-doing – KittenLS Oct 25 '22 at 17:25

0 Answers0