Android Instant Apps – Navigation Issue

Instant Apps on Google Play Store allow you to experience the application without actually downloading the app. Only the relevant parts of the application get downloaded as and when required.

The architecture for such an application is highly modularised, by features. There’s a base feature module, which houses the common or the shared functionality of the whole application, while individual feature modules implement specific parts of the application. Each of the feature modules is separate entry points which can be triggered independently. Thus, navigating between features and modules becomes very important.

While trying it out, I came across a weird issue where navigation was working fine, but the data that I was passing to the target feature module was not being sent through.

So, how do we pass data between various feature modules in an instant app? 

1. Using query parameters

Feature modules are triggered through verified app links. That means, each feature module specifies its entry point by using a url and a specific path segment.

For example:

The main entry point to your application can be specified by using this url:

https://my-awesome-app.com/news-list

And the detailed news can be displayed by implementing another feature module, whose entry point can be like this:

https://my-awesome-app.com/news-detail

If you would like to pass some data to your details screen, you can append that information with the url itself. Something like:

https://my-awesome-app.com/news-detail?article=34

// And launch the feature module
Intent intent = new Intent(Intent.ACTION_VIEW, Uri
.parse("https://my-awesome-app.com/news-detail?article=34");
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setPackage('YOUR_PACKAGE_NAME');

On the details feature module, you will need to extract this data from the url that will be provided. This works for passing small set of data.

2. Passing data using intents

This is quite easy to understand and also implement, since this also matches the approach that Android recommends. 

https://my-awesome-app.com/news-detail?article=34

// And launch the feature module
Intent intent = new Intent(Intent.ACTION_VIEW, Uri
.parse("https://my-awesome-app.com/news-detail?article=34");
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setPackage('YOUR_PACKAGE_NAME');

intent.putExtra('custom_data', "YOUR VALUE");

The only problem I faced in this approach. It worked only on Android O and above. The custom_data was never delivered to the target feature module on devices that are running Android N and less.

So, if you are having problems passing data between various feature modules and navigation between different screens. Passing data within the launch intent only worked on devices running on Android O and above.

Leave a Reply

Your email address will not be published. Required fields are marked *