Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we remove deep link data from intent

This is how I process deep link in my Activity.

I was wondering, how can I remove it from intent, after I had finished process it?

@Override
public void onCreate(Bundle savedInstanceState) {
    Utils.updateTheme(this);

    super.onCreate(savedInstanceState);

    Uri uri = this.getIntent().getData();
    if (uri != null && uri.isHierarchical()) {
        if (Constants.INVESTING_DEEP_LINK_PATH.equals(uri.getPath())) {
            // Processing deep link...

            // How can I remove deep link information from intent, after
            // finished procesing deep link...
        }
    }
}

I want to prevent the same data, when this activity onCreate is being executed again. For example, during configuration changes.


According to OPs, we can use the following way, to remove deep link info from intent after finished processing. However, it will yield another problem.

@Override
public void onCreate(Bundle savedInstanceState) {
    Utils.updateTheme(this);

    super.onCreate(savedInstanceState);

    Uri uri = intent.getData();
    if (uri != null && uri.isHierarchical()) {
        if (Constants.INVESTING_DEEP_LINK_PATH.equals(uri.getPath())) {
            // Processing deep link...

            intent.setData(null);
            setIntent(intent);
        }
    }
}
  1. Press on the deep link in email.
  2. We are able to find the deep link from intent.
  3. Press home button
  4. Press on the deep link in email.
  5. Not able to find the deep link from intent anymore.
like image 272
Cheok Yan Cheng Avatar asked Aug 14 '17 14:08

Cheok Yan Cheng


1 Answers

As @vlatkozelka mentioned, all you need to do is :

Intent clonedIntent = getIntent();
clonedIntent.setData(null);

and you are good to use clonedIntent.

like image 52
Nilesh Deokar Avatar answered Sep 29 '22 12:09

Nilesh Deokar