Like normal Android apps which you have to download from google play store, every Android Instant App has a URL like web applications and you can launch Instant Apps by clicking on that URL. whenever a URL is clicked which refers to Android Instant App, Google play services will download necessary code on user device. and that device runs the application.
Lets take an example of Vimeo Android application.
Open Google Play Services on your Android device and go to settings. there is an option “Use apps without installation” enable it.
Now any application on google play store which supports Instant Apps feature will have a “TRY NOW” button along with install button.
If you click on “TRY NOW” application will be launched without installation. If you like the app and want to use all of its features you can install it later.
Lets take example of Vimeo.
After you hit “TRY NOW” button play store application will get necessary application code.
User can go to settings and choose to Install application.
It is actually lighter version of a real Android App.
Developers have to enable deep links so a user can tap on any link and can immediately enjoy real Android App without installation.
Android Instant app work from 5.0 (API level 21) through Android 8.0 (API level 26).
Before you start building Android Instant Apps let me give you a brief introduction.
For example you have a Map Application. which allows users to find nearby places, share current location to other contacts via email.
Find nearby places – is a feature
Share contacts via email – is a feature
if users want to find nearby places, android will only download code which handles this feature, it will launch an Activity which will be responsible to find nearby places. and when user is done with finding nearby place Android OS will dispose this code.
And users want to download compete version of the app they can do so. so keep in mind it will be the same one app before and after installation.
so for each feature there will be an activity which will be launched if that feature is requested by user.
Step 1:
Create new project in Android Studio and select minimum API level 23.
Step 2:
In the Configure Activity dialog enter host name (your website URL) and in the URL box enter “/hello” and click finish.
The URL of your Main Activity will be “http://developine.com/hello”. If you open this URL from your Android device Main Activity will be launched.
Note: Android Instant apps only support https.
We have create a new project in Android Studio which includes support for Instant apps.
Now lets understand project structure.
Now we have two new modules base module and feature module in addition to app module in our Instant App Android Studio project.
Currently we have only one feature in our Android Application so we have one feature module in our project. we can add more features in our application (will do this shortly).
Android Instant App uses two new plugins.
A feature module applies “com.android.feature” plugin. you just write any feature module like a library module and the rest will be handled by tools.
As we already discussed every Android Instant app has base feature module and feature module.
An application can have multiple feature modules but one base feature is must (base feature module will have base code which is required for all other feature modules).
If your Android Instant app has only one feature than only one base feature module is enough, additional feature modules are not required.
Each feature module generates a corresponding feature APK which can be installed as instant app or can be launched through a URL.
Base feature module is always downloaded because it will have shared code, feature module code depends on base module.
Lets discuss and understand each module one by one.
This module is responsible to take all code (activities, fragments, drawables, resources) from all feature modules and build APK file.
If user choose to install Android Instant App this APK produced by App Module is installed on user device.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.developine.instantapp.app" />
This module uses ‘com.android.application’ plugin. And it includes all feature modules and base module.
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.developine.instantapp"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':feature')
implementation project(':base')
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.developine.instantapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="aia-compat-api-min-version"
android:value="1" />
</application>
</manifest>
Base module contains shared resources for all feature modules so all feature modules in application must depend on base module.
apply plugin: 'com.android.feature'
android {
compileSdkVersion 26
baseFeature true
defaultConfig {
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
api 'com.android.support:appcompat-v7:26.1.0'
api 'com.android.support.constraint:constraint-layout:1.0.2'
application project(':app')
feature project(':feature')
}
Conclusion
You have created an Android Instant App from scratch, You have learned about different types of modules in Android Instant Apps.
Recommended Reading :-
Develop Android Photo Gallery Application Complete Source Code
Integrate Firebase Native Advanced AdMob Ads in Android
If you have any question or feedback please write in comment section.
Subscribe our Youtube channel.