airbnb / airbnb/DeepLinkDispatch

No extras passed down to the activity when mode=singleTask?

Open
#170 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
4.4k
Forks
414
PR merge metrics
No merged PRs in 30d

Description

Hey guys - first kudos on this library ! I am using it heavily in our Android app where we started deep-linking to a bunch of pages.

One minor issue I have is I am sending a deep-link to myself (for some OAuth flow) and the activity that needs to be linked is already around on the navigation backstack and configured as singleTask since I don't want to be created again on the nav stack when firing the deep-link.

The deep-link works as my activity onNewIntent() method get called as expected but the intent doesn't contain any extras and I am going to have to parse the intent data myself, which is too bad, since that's the big value-add of this lib.

Here are some snippets of what I am doing:

Custom annotation for starters:

```java
package io.cens.snapshot.deeplink;

import com.airbnb.deeplinkdispatch.DeepLinkSpec;

import io.cens.snapshot.AppConfig;

@DeepLinkSpec(prefix = {AppConfig.APP_SCHEME})
public @interface SnapshotAppLink {
String[] value();
}
```

I am intercepting the link from my webview and fire a deep-link to myself.
```java
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith(AppConfig.APP_SCHEME)) {
final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url));
ActivityUtils.startActivity(InternalBrowser.this, intent, true); // since we are redirecting, remove this current activity
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
```
This is is activity that is configured as single task and initially pushed the webview-based activity so it's still around on the nav stack but not visible.

```java
@SnapshotAppLink("/auth")
public class ProfileActivity extends ActivityBase implements ProfileView {

....

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
mViewModel.onAuthenticated(intent);
}
```

And this is the method that parse out that intent and would expect to have state and code as extras since they end up being serialized as query params in the deep-link url.

```java
public void onAuthenticated(Intent intent) {
if (intent == null || intent.getExtras() == null)
return;

final Bundle extras = intent.getExtras();
final String state = extras.getString("state");
final String code = extras.getString("code");

if (TextUtils.equals(state, mState)) {
Logger.d(TAG, "Authentication completed. code=%s", code);
// TODO: send code to server
}
}
```

Also, I may doing something wrong and in that case, I apologize for the bother. Thanks!

Contributor guide

Open the contributing guide

Research direction

Start at ActivityUtils.startActivity and the generated deep-link handling associated with @DeepLinkSpec, then trace how an existing singleTask activity receives onNewIntent. Verify how query parameters become extras and compare that path with normal activity creation. Done means state and code are available as extras in onNewIntent for the reported deep-link flow, with coverage for the singleTask case.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.