I have integrated BranchIO in splash activity(i.e. The Launcher Activity).
case 1: When the app is not in the background and I click on the deep link, SplashActivity is opened. (Works fine)
case 2: When I am already logged in and put the app in the background, on click on the deep link the app again restarts with Splash Activity
I want the app to be resumed in whichever state it was left when I click on the deep link. How to achieve this?
One Solution would be to handle navigation in SplashActivity whenever the app is opened via link, but that is not feasible here. We just want to launch the app in whichever state it was left before.
In splash screen's onCreate check that splash screen is root activity or not. if it root task then finish. because your app is already opened.
if(isTaskRoot()){
finish()
}
Related
I am launching YouTube with our floating window timer.
when time finishes, I want to come back to the app. Currently I am doing this by startIntent(MainActivity) but it open a fresh app that is an issue, I want to open previous opened fragment.
I used Single Activity Navigation Component Architecture in my App
add flag in your intent
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
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.
In my app, it starts with the Splash Screen. Then the user login and already reach to Dashboard activity. I finish the Splash and Login activities from the backstack.
But when the user open the app again from Zapya, the app load new splash activity on top of the existing activity stack.
When the user tap on Back button, the splash activity disappears and the Dashboard activity display again.
According to my knowledge, the app should normally show the topmost activity when it already exists in the memory.
Please, suggest me is there anythings should I modify or configure?
Edit: This is a known bug and there is various ways to solve this problem. I've solved this problem by this stackoverflow answer.
You can also learn in the following post too.
App restarts rather than resumes
I'm working on a launcher app that basically launches other installed apps on the device with an explicit intent and I have a edge case scenario:
An Activity (Act) creates an intent of an application (App) and starts it by calling startActivity(intent).
App get launched, my Activity going to "stop" state.
After a while I want to get back to my application so I click on "back" hard button that closes App and bring my Application to foreground (resume state).
This is the wanted behaviour.
Here is the edge case:
If I click on the "recent applications" hard button (square icon) while on App is launched, history stack is lost, and when I return to App, and click on "back" hard button - App exists to the Launcher screen and onResume of my application is being called.
I searched the web for a solution for couple of hours now, maybe I'll find a solution here.
Thanks
It seems to me you should set android:alwaysRetainTaskState true in your root activity.
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.