android proper implementation for deep linking - android

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

Related

Navigation Component implicit deep link back press exits the app

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.

How do mobiles applications store their history. What is the mechanism

Every browser stores history of web pages we visit, I am curious if mobile apps work similarly, what is the mechanism.
What happens when we press the back button, how does the app know which page to open up?
What you are calling "pages" is actually termed as "activities" in android. To answer your question, every android app maintains it's own Backstack to keep track of the visited activities.
According to the documentation,
The activities are arranged in a stack—the back stack)—in the order in which each activity is opened. For example, an email app might have one activity to show a list of new messages. When the user selects a message, a new activity opens to view that message. This new activity is added to the back stack. If the user presses the Back button, that new activity is finished and popped off the stack. The following video provides a good overview of how the back stack works.

Generate back stack for deep linking from an email URL

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.

deep linking - handle onBackPressed in situation where was already launched

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.

How can I use back button while loading a page in an Android WebView?

I have a link in my application that triggers a webview to open from webview.loadUrl(...).
Sometimes it's takes quite a while to load the page, and in these cases I want to be able to use the built in back button on the phone to cancel the loading and go back to my application.
How do I do this? Is there some way I can listen to the backbutton while loading the url?
The back button is intended to move the user backwards through the activity stack.
I think it is possible you are handling too many user actions in a single Activity. As a general rule, any kind of user 'select' should trigger a new Activity.
Whenever the user does something that should be cancelable with the back button, you should trigger a new internal Activity via an Intent. Then the OS will give you this behavior automatically.

Categories

Resources