title: What exactly is intent.resolveActivity(getPackageManager()) doing?
body: <p>I'm going through the <a href="https://codelabs.developers.google.com/codelabs/android-training-activity-with-implicit-intent/index.html?index=..%2F..android-training#0" rel="noreferrer">the Android Developer Tutorials</a> and I encountered a line of code that I do not understand.</p>
  
  <p>This is the line of code (found on 4th page of the Android Developer tutorials.)</p>
  
  <pre><code>    Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
      if (intent.resolveActivity(getPackageManager()) != null) {
          startActivity(intent);
      }
  </code></pre>
  
  <p>I have a couple of questions.</p>
  
  <p>1) <code>Intent.ACTION_VIEW</code> <a href="https://developer.android.com/reference/android/content/Intent.html#ACTION_VIEW" rel="noreferrer">documentation</a> says that it simply displays data to the user. I understand that the app it chooses will depend on the type of data to be displayed. For instance, in this case, the webpage is being parsed as a uri data type. But what kind of implicit intent is being created here? In the backend, can I think of Android as going through all the classes in my phone and seeing which one has the intent filter that can possibly handle the data and creating the intent structure to start this class that it found?</p>
  
  <p>2) What happens if it finds multiple classes that can handle this? Does it simply choose the default or ask the user to choose what app it wants to run in on? When I ran the code on my phone, it simply started the Samsung Internet App by default.</p>
  
  <p>3) This is actually my main question. If the intent has already been linked to a class to start, why bother with <code>intent.resolveActivity(getPackageManager())</code>  at all? Its <a href="https://developer.android.com/reference/android/content/Intent.html#resolveActivity(android.content.pm.PackageManager)" rel="noreferrer">documentation</a> specifies how it handles the class if a class is returned. So alright, a class is returned. But also this class that it returns is not 'incorporated' in my <code>intent</code> at any line of my code, which makes me think that <code>Intent.ACTION_VIEW</code> has somehow already handled it for me. </p>
  
  <p>This is going to a leap, but would I be sort-of correct in saying that <code>Intent.ACTION_VIEW</code> runs <code>intent.resolveActivity(getPackageManager())</code> or another function that does similar and somehow incorporates the class it returns into my intent?</p>
  
  <p>4) Also, out of curiosity, what is inside the <a href="https://developer.android.com/reference/android/content/pm/PackageManager.html" rel="noreferrer">package manager class</a>? I read <a href="https://stackoverflow.com/questions/44620981/android-intents-resolveactivity-and-package-manager">here</a> that it is like a directory of application data. Would I be correct in saying that? What kind of data does it keep about the application and how can I go about accessing them. The documentation doesn't seem to help much.</p>