I'm going through the the Android Developer Tutorials and I encountered a line of code that I do not understand.
This is the line of code (found on 4th page of the Android Developer tutorials.)
Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
I have a couple of questions.
1) Intent.ACTION_VIEW
documentation 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?
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.
3) This is actually my main question. If the intent has already been linked to a class to start, why bother with intent.resolveActivity(getPackageManager())
at all? Its documentation 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 intent
at any line of my code, which makes me think that Intent.ACTION_VIEW
has somehow already handled it for me.
This is going to a leap, but would I be sort-of correct in saying that Intent.ACTION_VIEW
runs intent.resolveActivity(getPackageManager())
or another function that does similar and somehow incorporates the class it returns into my intent?
4) Also, out of curiosity, what is inside the package manager class? I read here 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.