-
Notifications
You must be signed in to change notification settings - Fork 534
Deep linking loads multiple instances of app on android #37
Comments
Thanks for the kind words :) I don't have a whatsapp, but tried to reproduce it with the Inbox app and couldn't. What I did:
Also, can navigate back to the Inbox app by clicking on the square button. Can you please provide a step-by-step guide on how I can try to reproduce it?
Feels like whatsapp opened url link in his inner webview instead of launching your app. Especially if you can't see it in recent apps list. Android app can't launch another application inside of himself. |
Hi. Thanks for getting back to me so quickly. Yes you are right it does appear as if whatsapp is loading it as some kind of internal webview. I guess that is a separate discussion of why it does that. If I email myself a link in the gmail app (I dont have inbox) I get different behaviour this time. The app loads as a proper app outside of gmail (not in some kind of internal webview). However, if I already have the app open it duplicates the app, so that if i look at my recent apps there are two versions of it open. Just in case this was something strange i did for my app I did the following
You see there are two copies. The one that was loaded on step 6 is apparently ignored when i click on the link in gmail. What do you think? Thanks again, |
@mklilley thanks for the step-by-step guide, that helped. After some experiments and debugging I found, that this is an Android feature, not a plugin bug. I'll explain why and how it can be changed. At first I tried to use Inbox app. I launched my TestApp, then pressed home button, then in the Inbox app pressed the link. As a result - existing instance of the TestApp was launched, no new instance is created. Then I used Gmail app, and suddenly it created a new instance of the TestApp. Which is strange, since application is the same, link is the same. The only thing that has changed is the app, in what the link was pressed. This means, that they are sending different types on Intents to the Android. Intent from the Inbox doesn't lead to creation of the TestApp's new instance. To confirm that I launched the app in debug mode from the AndroidStudio and placed a break point in the After looking into <activity
android:name="MainActivity"
android:launchMode="singleTop"
....> From the android documentation you can find, that To prevent that from happening you can change
But in the case of Ionic/Cordova apps, which consist only of one activity and all navigation is executed within the WebView - that can be fine. But make sure to test it carefully. |
@TonivdW I think in your case the problem is the same, as I described above. This is an Android behaviour, not a plugin thing. In some way - yes, plugin can be considered as responsible for that, since it add's the feature for launching the app from the link. But it can't control what Intents it receives and if new instance of the app is created. As an experiment, you can try to add android:allowTaskReparenting="true" to the <activity
android:name="MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:label="@string/activity_name"
android:launchMode="singleInstance"
android:allowTaskReparenting="true"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:windowSoftInputMode="adjustResize"> |
@nikDemyankov This works like a charm, thank you so much! It is thanks to people like you that people like me can get anywhere with making apps. You are a star! Matt |
@mklilley thanks :) |
@nikDemyankov My testing shows that setting allowTaskReparenting is not needed. I switched android:launchMode from the default (singleTop) to what you mentioned above (singleInstance) and that alone did the trick. The app is now started outside the context of the calling app just like it should (for my purpose) |
@TonivdW Thanks :) I'll update the readme, so if someone will hit the same issue - they would know why and how to fix it. Created an issue for that so I would not forget. Leaving this one open for the newcomers, will close it when the docs are updated. |
Unfortunately I encountered and issue with changing the lauchmode to singleInstance... |
Don't know, I think you should ask him... But my guess, is that it will require some experiments with PushHandleActivity or GCMIntentService. |
The reason I was asking you is that the universal links plugin does manage the app to be brought to the foreground, even if the setting is singleInstance, so I was guessing your code also has to actively make that happen. Or is it the OS that is doing this? In that case the OS apparently is handling push notifications differently than universal links. |
UL plugin doesn't open the app. This is OS doing. It only handles the intent, that was used to launch the app. And by "handles" I mean it just read's information from it and nothing more. In the case of the push notification it is a bit different. When user clicks on the notification - plugin launches PushHandleActivity, which handles the notification, and then launches MainActivity , if needed. So if something can be done regarding all of that - then it's in there. But if I'm wrong - please, point me where to change and what :) |
I did some further testing and it seems that if I use singleTask for lauchMode, both UL and plugin-push work like I would like it to work. |
|
The original value was singleTop. |
Ah, yes, you are right. Great :) I think it should be fine. But some extra testing is always a good idea. |
@nikDemyankov Thanks for the awesome work on this :) And @TonivdW, thanks for basically doing my work for me - I had the same issue with push notifications, 👍 |
@mattwoberts great, thanks :) |
I have this plugin ( version 1.1.2) installed on top of Ionic. I'm trying to change android:launchMode to single instance as recommended in thees comments but building always reverts launchMode to single top. How can I make it not revert back to that? |
On every build Ionic rewrites
Haven't tested the JS code above, but you should get the idea on what it does. |
@nikDemyankov is it not enough to just add the preference in config.xml?
|
@headshota yes, you are right. Missed that option in the docs in the first place. That's why suggested a hook. |
Following nordnet#37 and nordnet#38, updated README Cordova config preferences section with a new sub-section to detail how to prevent Android from creating multiple instances of the App when clicking on a link from another App.
Word of caution, had issues with the Facebook login when setting: |
Yup, unfortunately this setting breaks other things like the cordova-plugin-camera. See this error: http://stackoverflow.com/questions/38878963/ionic-cordova-camera-plugin-error-on-android and https://issues.apache.org/jira/browse/CB-3452. So the question is how can I prevent the issue mentioned here without using |
@jacquesdev I don't think you can... That preference controls exactly that. |
Hi @jacquesdev, so did you find a solution for that ? I am in the exact same position where I have to choose whether I want Universal Links to work properly (setting Is there a way to get both features working at the same time ? I really don't want to have to choose one of the two... |
Unfortunately not :( I have opted to not use the singleInstance option, on balance it's the only real solution for the moment. |
I just found another option singleTask which seems to satisfy both cordova-universal-links-plugin and cordova-camera-plugin. I have tested it on an a new android phone and on an old android tablet and it works fine so far. I hope it won't cause any new problems in the future, since in the documentation it says "not recommended for general use". |
👋 Hi! Thank you for your interest in this repo. 😢 We are not using nordnet/cordova-universal-links-plugin anymore, and we lack the manpower and the experience needed to maintain it. We are aware of the inconveniece that this may cause you. Feel free to use it as is, or create your own fork. 🔒 This will now be closed & locked. ℹ️ Please see #160 for more information. |
I am creating my app using Ionic and am testing the app on Android version 5.1.1.
I find that using the plugin does indeed allow the app to be launched when I click on a particular link which is lovely, thanks.
The issue is that if I already have the app open and then I click on a link inside of e.g. whatsapp, then a new instance of the app loads inside of whatsapp instead of using the already open app. This creates a strange user experience because in order to return to whatsapp I have to navigate backwards several times , whereas I would expect to just be able to switch from my app back to whatsapp using the familiar square button that allows you to see all open apps.
Thanks for taking to time to develop this plugin, it is very useful, I am just trying to understand if this is intended behaviour or a bug.
Thanks,
Matt
The text was updated successfully, but these errors were encountered: