-->

Dynamic Links- With position or Childkey

You are done, dynamic Links should now work properly.

If you fail to understand, check tutorial in skteacher application for reference.

Create project if you have not already done so.

Then select your project.


Now click on Menu


Scroll down and select dynamic Links.


Add your dynamic link by completing the suggestion in the edittext field (it is recommended to add your app name as part of link).

After adding the link. Copy it, we will need it in app integration.


Now we had over to app integration. Open your project. In MainActivity, we add the dynamic Links component and a shared preference component.


Name the shared preference anything you like (but you should remember the name, I advise you stick to details as tutorial)


Name the dynamic link anything you like. I have named mine dynLink

Now  in events, open onCreate. Add the block Setdatahost block. Paste your link you got earlier from your firebase.


Go back to events and add onBecoming visible, open it and add block as below

Go back, and select components in event. Click the plus (+) and Add as below (success and failure listeners).


Open onSuccess. Here we will check if dynamic link is empty or not then handle the outcome accordingly.

According to the logic below, if dynamic link is empty (if no dynamic link is received, we just navigate to home activity if it's not empty we handle it by capturing the dynamic link value and storing it in shared preference and moving to the page where the link will be processed.

"The replace link string holds link to your playstore or any website. It has to be exact link as when generating link (details ahead)".

Let's move on to the activity where we will use the caught dynamic link. In onCreate of the activity, we check if dynamic link we carried in shared preference from main activity is empty or not. If the shared preference is empty or null then we do nothing otherwise we save contents of shared preference in string "key" (create string key or any name you wish).

Choose between the two bottom onCreate logic according to which approach you will take.

1.Do this if you will use childkey!

2.Do this if you will use position!

Go to component event and add child adedd and child changed


Create a liststring (name it anything, in my case i named it uid). Add childkeys to this liststring.


Let's go to view-bind. Open onBindCustomView.
Here we check if the shared preference that carries dynamic link is empty or not. If it's empty we just bind custom view normally. If it's not empty then we can handle dynamic link.

Handling methods:
You choose one!

1. Child key
2. Position

1.Child Key
Check if string "key" (name of your string) is equal to childkey at a position.

What will happen is that we will get all the data at that position which equals the key and switch activity thereby leading you to the exact location of the content you shared.

2.Position
With position. Add the similar logic, just change position to "num" (a number variable you stored your shared preference content in onCreate).

What happens is that content at that position will be captured then we move to another activity where we are able to view the content.

Finally let's have a look at the logic we implement in activity where we share dynamic link from.

Before moving to the activity, we get position or Childkey in shared preference. 

(Choose one depending on the method you have chosen)

Childkey

Position

In the activity, add a dynamic link component with the name like you added in MainActivity (name can be different).

Create these strings;
1.Description
2.Title
3.Position
4.shortDyn

Let's look at the share button. Add logic as below (just change uri prefix and description text to your own).

Add share button to layout.



*Uri prefix should be same as you added in MainActivity onBecomingVisible.

*Link should be exact as link in onCreate onSuccess listener

Full button logic;

You are done, dynamic Links should now work properly.

If you fail to understand, check tutorial in skteacher application for reference.

See Also :