In Android, it is quite usual for users to witness a jump from one application to another as a part of the whole process, for example, searching for a location on the browser and witnessing a direct jump into Google Maps or receiving payment links in Messages Application (SMS) and on clicking jumping to PayPal or GPay (Google Pay). This process of taking users from one application to another is achieved by passing the Intent to the system. Intents, in general, are used for navigating among various activities within the same application, but note, is not limited to one single application, i.e., they can be utilized from moving from one application to another as well.
Intents could be Implicit, for instance, calling intended actions and explicit as well, such as opening another activity after some operations like onClick or anything else. Below are some application of Intents:
- Sending the User to Another App
- Getting a Result from an Activity
- Allowing Other Apps to Start Your Activity
The collaborative nature of Android applications only results in a better user experience. The question here is if the intent is for an application that is not present in the device, what’s the next call?
Some Important Method of Intent and its Description
|Context.startActivity()||This is to launch a new activity or get an existing activity to be action.|
|Context.startService()||This is to start a new service or deliver instructions for an existing service.|
|Context.sendBroadcast()||This is to deliver the message to broadcast receivers.|
Deep Link is an URL that redirects the device to the API of that Missing Application and then service is run on the system to check if a version of that application exists on the device. For time being, let’s assume that the application is not available on the device and no previous versions ever existed. This service then makes a call to the Play Store from the device and the application appears, just a matter of download.
Not deviating from the topic, there are a few examples that already exist in Android Studio for redirecting to other applications, for example, Dialing Numbers, Sending SMSs, Opening Settings, etc. Everyday examples include redirecting to YouTube, Maps, WhatsApp, Facebook, etc. Android community, especially the Kotlin Community is at its zenith every single impending day. Kotlin has witnessed a huge amount of sudden growth in the past few years and could be one of the vital tools in the future replacing Java & possibly Julia also.
Types of Android Intents
There are two types of intents in android:
- Implicit and
1. Implicit Intent
Implicit Intent doesn’t specify the component. In such a case, intent provides information on available components provided by the system that is to be invoked. For example, you may write the following code to view the webpage.
Intent intent=new Intent(Intent.ACTION_VIEW);
In the below images, no component is specified, instead an action is performed i.e. a webpage is going to be opened. As you type the name of your desired webpage and click on ‘CLICK’ button. Your webpage is opened.
2. Explicit Intent
Explicit Intent specifies the component. In such a case, intent provides the external class to be invoked.
Intent i = new Intent(getApplicationContext(), ActivityTwo.class);
In the below example, there are two activities (FirstActivity, SecondActivity). When you click on the ‘GO TO OTHER ACTIVITY’ Button in the FirstActivity, then you move to the SecondActivity. When you click on the ‘GO TO HOME ACTIVITY’ button in the SecondActivity, then you move to the first activity. This is getting done through Explicit Intent.
Note: To know more about the types of intent with example code please refer to Implicit and Explicit Intents with Examples.