37
A light introduction to the Android intent system
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
An intent is an abstract description of an operation to be performed
. This simply means that anytime you hear or read the word intent
you should automatically think to yourself, ok, some sort of work is about to be done. An intent can also be thought of as the glue between activities, as it is often used to share information.1) Explicit Intents : this is the kind of intent that has a specified component(class) to be run, often explicit intents will not include any other information. They are a way for an application to launch various internal activities as the user navigates through the app.
new Intent(getActivity(), MainActivity.class)
2) Implicit Intents : no component(class) is specified, instead we must provide additional information for the system to determine which of the available components is best to run for that intent.
1) The component name : this is literally the name of the component that we want the intent to run. For us it the the
MainActivity.class
. While the component name is optional, it is a very important piece of information to provide, especially when defining an explicit intent. No component name, no explicit intent. Without a component name the intent becomes implicit
and the Android system must use other information(action, data and category) to determine what component is the appropriate one to call.component name
because in our example that is only what we use. If you wish to learn more about the intent information then you should read the documentation HERE
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
component name
and making this intent an explicit intent. Lastly we call startActivity(intent)
, which will use the information stored inside of the intent object to open the correct activity. With that being said we now have a light understanding on what an intent is and what it does.37