Deep Links in Android: Getting Started
In this tutorial you’ll learn how to use intent filters to create deep links in to your Android app. By Harun Wangereka.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Deep Links in Android: Getting Started
20 mins
- Getting Started
- Understanding Deep Links
- Building Blocks of a Deep Link
- Understanding Intent Filters
- Creating a Deep Link
- Testing Your Deep Links
- Getting Data From Incoming Intents
- Adding Custom Schemes
- Handling Multiple URIs in One Activity
- Handling Deep Links When the User Doesn’t Have Your App Installed
- Creating a Subdomain for Your Dynamic Link
- Creating a Firebase Dynamic Link
- Handling Dynamic Links in Your App
- Viewing Analytics Data
- Invoking a Deep Link Multiple Times
- Where To Go From Here?
Viewing Analytics Data
You added the necessary logic to record analytic events. Now, go to the Firebase console and open the Dynamic Links section. You’ll see something like this:
As you can see, you have the data on the number of:
- Clicks
- First opens
- Re-opens
You can expand the link and see more insights about how your Dynamic Link is fairing.
Invoking a Deep Link Multiple Times
If your deep link activity stays in the foreground, and you invoke the deep link again, multiple instances of the activity stay in the backstack. To prevent this, add the following attribute to your activity definition in AndroidManifest.xml:
android:launchMode="singleTask"
This code ensures only one instance of the activity can exist at a single time. It also helps you avoid running into unexpected backstack issues.
In PromoActivity.kt, add the following code below showDynamicLinkOffer
:
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.let { newIntent ->
handleIntent(newIntent)
}
}
Here you call handleIntent()
with the intent received in onNewIntent
which is called when your activity is in the foreground and receives a new intent. Depending on which method you use, you can call handleFirebaseDynamicLinks()
or handleIntent()
.
Build and run. Click the link from Firebase Dynamic Link. You’ll see:
Now when you invoke the deep link multiple times, you’ll have the correct flow without unexpected issues.
Where To Go From Here?
Download the final version of this project using the Download Materials button at the top or bottom of this tutorial.
Congratulations! You learned how to use deep links to improve your app’s user experience. You also learned how to take advantage of Firebase Dynamic Links to create deep links that work across all platforms.
To learn how to create deep links when using the Jetpack Navigation Component, check out Navigation Component for Android Part 2: Graphs and Deep Links.
I hope you enjoyed the tutorial. If you have any questions or comments, please join the forum discussion below.