0

Im planning to migrate the current app to an instant app. So i was wondering is it possible to navigate from one sub instant feature module to another instant feature module. For example i might be on a details feature which holds necessary information about a product, so if the user is interested in buying that product then i can navigate the user to payment feature module( google payments api currently doesn't serve my purpose due to business rules) so is this kind of navigation currently supported among instant modules?

bostan
  • 373
  • 2
  • 8

2 Answers2

5

Of course this is supported, otherwise it would be very limited to use Instant Apps.

You must use AppLinks to open feature modules. After you made the call, Android will be downloading that feature if required.

For example this is the flow of opening detail feature from main feature used in Google Samples.

Creating the Intent:

@NonNull
private static Intent getDetailActivityStartIntent(Context context,
                                                   int position,
                                                   PhotoViewHolder holder) {
    final Intent intent = new Intent(Intent.ACTION_VIEW,
            Uri.parse("https://multi-feature.instantappsample.com/detail/" + position));
    intent.setPackage(context.getPackageName());
    intent.addCategory(Intent.CATEGORY_BROWSABLE);

    TextView author =
            holder.itemView.findViewById(com.example.android.unsplash.base.R.id.author);

    // Working around unboxing issues with multiple dex files on platforms prior to N.
    intent.putExtra(IntentUtil.SELECTED_ITEM_POSITION, position);
    intent.putExtra(IntentUtil.FONT_SIZE, author.getTextSize());
    intent.putExtra(IntentUtil.PADDING,
            new Rect(author.getPaddingLeft(),
                    author.getPaddingTop(),
                    author.getPaddingRight(),
                    author.getPaddingBottom()));
    intent.putExtra(IntentUtil.TEXT_COLOR, author.getCurrentTextColor());
    return intent;
}

Starting it:

final Intent intent = getDetailActivityStartIntent(activity, position, pvh);
final ActivityOptions activityOptions = getActivityOptions(pvh);
activity.startActivityForResult(intent, IntentUtil.REQUEST_CODE, 
    activityOptions.toBundle());

Finishing for result is just the same as non Instant Apps.

Set the result in DetailActivity and finish it. Get the result in onActivityResult of MainActivity.

Mustafa Berkay Mutlu
  • 1,929
  • 1
  • 25
  • 37
1

Yes, Android Instant Applications support navigation from one sub instant feature module to another instant feature module.
(Example: details feature -> payment feature)

You can refer google developers webpage :

  • Always consider your entry points.
  • Each feature within the instant app has at least one Activity that acts as the entry-point for that feature.
  • Also, an activity cannot launch another activity directly within an instant app; rather, it must request the URL address that corresponds to that activity.
  • You can navigate by building an INTENT(request URL address); to open payment feature(feature2) you may call this from details feature(feature1).
  • When users request a feature from an instant app, they receive only the code necessary to run that specific feature, no more and no less.
  • By doing this, you are following the entry point concept.

Sample code examples related to feature navigation can be checked at this GitHub link.

ManmeetP
  • 801
  • 7
  • 17