It is possible to call an Activity in another App from your App by using an Implicit Intent.
In the last Article you saw how to use an Explicit intent to call an Activity in
the same App.
A Scenario can be if you want to send a Text Message when the user clicks on a Button in your App.
To achieve this you need to know a few basic concepts:
1. Action
In an Explicit Intent you need to specify the Action – like Email, Message, Call – basically what kind of Intents you want to use.
Intent intent = new Intent(Intent.ACTION_SEND);
Here ACTION_SEND tells android to use an Activity which can do this operation.
2. Message or Information
To send additional information you need to use putExtra method.
intent.putExtra(Intent.EXTRA_TEXT, “Hello Ankur”);
3. Intent Filters
So you might be wondering how Android knows which Activities can perform this operation.
It does this using the Intent Filter defined in the App’s Manifest File.
So if you want your App to handle an ACTION_SEND action you need to add an Intent Filter to your Manifest file.
Like
<activity>
<intent-filter>
—-
</intent-filter>
</activity>
When a request comes Android compares the Action specified with every App’s intent-filter and then presents you with a list of Apps which can handle the operation.
Source Code – https://github.com/ankur-srivastava/HelloAndroid/blob/master/app/src/main/java/com/edocent/helloandroid/MainActivity.java
You will learn how to test this concept in the next Article.
One thought on “Android Basics – Call an Activity in another App using Implicit Intent”