I basically try to mix these two tutorials:
deep linking from notification with back stack
deep linking from url
What I want to do is to launch a specific activity of my app when the user click on a url in an email. When the activity is launched I want the user to be able to press back and to go to the parent activity like if the user had land on this page following the normal journey throw the app.
I know how to open the specific activity but I don't know how to generate the backstack. In the example they are able to manage the backstack as the deep linking comes from a notification generated by the app itself, so they can create a pending intent. In my case the link is from an email so I can't do that.
Any idea?
Create activity without content view for handling incoming intents. This RouterActivity handles intents and decides what activities should be started with startActivities (TaskStackBuilder) after that it finishes itself with finish().
RouterActivity should use theme: #android:style/Theme.NoDisplay (use Activity instead of AppCompatActivity) and should not set any content view
so user will have no clue that there was any activity started before desired one.
Related
I've an implicit deep link created just like mentioned in the docs.
https://developer.android.com/guide/navigation/navigation-deep-link#implicit
implicit - domain.com/
When I click on it, yhis opens a new instance of the activity, mentioned in the docs đź‘Ť
If I press back it exits the app.
The documentation says it should go back to the previous app and reloads that fragment, what am I doing wrong here?
If the flag is not set, you remain on the task stack of the previous app where the implicit deep link was triggered. In this case, the Back button takes you back to the previous app, while the Up button starts your app's task on the hierarchical parent destination within your navigation graph.
What's the difference between back button and up button?
The documentation says it should go back to the previous app and reloads that fragment, what am I doing wrong here?
The docs you've specifically quote says that the system back will take you back to the app that deep linked into your app, so the behavior you are seeing is expected.
For example, if you click a link in the Discord app and that app doesn't use FLAG_ACTIVITY_NEW_TASK, then your app exists on Discord's task stack and are part of its back stack. This means that the system back button is expected to take you back to Discord.
As per the Principles of Navigation, the Up button functions differently when your activity is placed on another app's task stack:
The Up button never exists your app
When your app is launched using a deep link on another app's task, Up transitions users back to your app’s task and through a simulated back stack and not to the app that triggered the deep link. The Back button, however, does take you back to the other app.
So it is expected that the Up button always keeps the user in your app and the Up button will never return the user to the Discord app.
Scenario :
In my application i have enabled app linking. So when an App link is triggered, i have set a dummy AppLinkActivity (opens as "singleTask" to avoid creation of new task) to receive and handle the url received through the app link. While handling the url, i have to check whether the app was showing the "DownloadActivity", if so then i have to show a dialog.
So when an App link is triggered, i will have the already existing task with existing activities and on top of that will be the AppLinkingActivity. In this case i have no way to know what the previous activity was, since i cannot pass anything via an intent.
What i want to do
When the AppLinkingActivity is opened via an app link, is there any way by which i can find out what was the last shown activity(of my app) before AppLinkingActivity in the same task?
--Alternatively--
If i exclude the "singleTask" in manifest then the AppLinkingActivity is opened in a new task. In this scenario, is there any way by which i can get the last shown(or topmost) activity in the previous task? If yes, i also need a way to navigate to that topmost activity in the previous task? In this scenario if i simply finish() AppLinkingActivity, then the control goes back to the which ever source that triggered the app link like browser or gmail app etc.
Is any of the above two requirements is possible?
I have couple activities in one app.
There is a God Activity which is like a home page
and there are subsidiary activities like profiles.
for my understanding is, when we use deep linking, it should link to a specific content. for example, user X. and when people click the href, it should open user X's profile page.
My question is, when people click www.example.com/user-x
should i launch from the start of the app, and open profile page automatically after that. Or should i just open profile page directly.
opening from the start of the app may give me delay so user will not see what they want to see at once.opening directly will need to implement back key pressed handler to go to the main page ----i guess?
Also, is it better to create a stand alone activity to handle all the income urls to tell which activity should be start?
It should link directly to Activity which shows User X's profile and not redirect through your GodActivity
No, a single activity should not be used to handle all redirects
Don't make user go to GodActivity on pressing back. Back is supposed to remove activity from BackStack not add new ones
Pressing the back button in ActionBar should take user to the Parent activity, GodActivity in your case
Is there a way for a deep link into my app to simply resume the app if it's already running and preserve the activity stack?
Lets say I have activities A, B. Both are singleTop.
A is my main activity and it is also the one that has the intent filter for the deep link.
If I open A, and B on top. Then pause the app to go to a browser to deep link into my app. It opens just A where I want it to have B on top of A.
Is this possible?
Maybe your deep link takes the app to a dummy activity C (and that is the only way to start that activity, for simplicity) and from there you find your way back to the previous activity (either A or B).
i want to implement deep-linking as requested here:
https://developers.google.com/app-indexing/android/test
"The back button returns to the previous screen.
After opening a deep link, pressing 'Back' from the deep linked content should lead users directly back to the search results page. Test this by creating an HTML page with deep links (described below). After following one of the deep links from the browser to the app content, the 'Back' button should take the user back to the page containing the deep link. It should not lead to other content within the app or prompt for confirmation."
my problem is when my app is launched - > first activity is Started-> pressing home button -> using deeplinking (and now i am starting a different activity) -> back button is not getting me back to search results page. instead, onResume() called on the first activity. System.exit(0) not helping as it makes the app relaunch again (when onBackpressed is called).
thanks
It's depend on what you want to do.
1. Start a new application for deeplink
2. Start new application if app is already not running and if running us that app and go to appropriate activity.
in 1st case it's possible to come back to page from where deeplink was launched but I am not sure about 2nd case when app is already running.