Android deep link to resume app - android

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).

Related

Resume browsing on Chrome Custom Tab

I am working on an special oauth flow on Android. I have an activity A which can delegate the authentication to a webpage using a CustomTabIntent launched by UI-less Activity B. Once the authentication finishes it redirects with a deep link that B intercepts and closes the activities clearing the backstack which looks like
A -> B -> CustomTab
So when it finishes B with FLAG_ACTIVITY_CLEAR_TOP it goes back to A
Now for a new feature the difference is that the deep link intercepted by B needs to open C to do some permission management. I am able to do that by just finishing B and launching C. However once C finishes I need to take my user back to the browser to finish the authentication so I need a backstack that looks like
A -> B -> CustomTab ->C
But I seem unable to launch C on top of CustomTab without closing the later. Closing it is not an option since I need my user to continue at the point where he left the browser. Another option would be if I could close the Custom Tab but later resume the browser at the state it was closed. But I haven't been able to find a way to do neither of these.
Now to complicate the problem more, C could be a new instance of A ending with something like
A -> B -> CustomTab ->A2
Therefore launching my activities as single tasks is not an option.
If someone has been able to launch an activity on top of a custom tab without closing it I would really appreciate your help. Or if you have any other idea to tackle this problem it would be welcome.

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.

android proper implementation for deep linking

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

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.

Back button takes me to launcher activity not deep-linker activity

Following procedure:
Start my application, Stack: [HomeActivity]
Going to Facebook, using a deep link to get into Activity X
Pressing back button results in getting back to HomeActivity instead of Facebook
Expected
Start my application, Stack: [HomeActivity]
Going to Facebook, using a deep link to get into Activity X
Pressing back button results in getting back to Facebook App
I get the expected behavior when my application is not started at all beforehand. I see that other apps like Instagram does managed to get this working properly. So even if your application is running in the background it takes you back to the activity which issued the deep-link intent.
My activity has launchMode="singleTop", onBackPressed() is not overriden, so it calls the super class implementation.
What am I missing here to get this right?
I debugged it and onBackPressed() eventually calls finish(), yet it gets me back to my application instead of Facebook.
Add
android:taskAffinity=""
to the <activity> tag for your "deep-linked Activity" in the manifest.
What is happening is that Facebook is launching your "deep linked Activity" with Intent.FLAG_ACTIVITY_NEW_TASK (you should be able to verify this by checking the content of the Intent in your Activity in onCreate() or onNewIntent().
If your app is already running, Android brings your existing task to the foreground and launches the "deep-linked Activity" on top of that task. When you then press BACK, it just finishes your "deep linked Activity" and drops you into your existing task.
Android does this because all of your activities share the same taskAffinity, so when it needs to create a new task for your app, it will first try to find an existing task with the same affinity.
If you set the taskAffinity of your "deep linked Activity" so that it is empty, this should prevent Android from looking for an existing task to launch the Activity into. It will just create a new task and launch your "deep linked Activity" into that new task. Then, when you press BACK, your Activity is finished, and the task will become empty, so the task will be finished and it will drop you back into the previous task in the task stack (which should be Facebook, since your app was launched from there).
The reason is that the launch of Facebook starts a new task. Back always navigates up the activity stack within a task.
If you have control over the intent which launches Facebook, there are flags which control the task the activity is launched within. The default is to launch within the same task.
I suspect that Intent.FLAG_ACTIVITY_NEW_TASK is being added intentionally by the system -- so this may be by design (working as intended).
PS: This presentation will teach you all you ever need to know about android activities and tasks: http://www.slideshare.net/RanNachmany/manipulating-android-tasks-and-back-stack

Categories

Resources