1

My problem is with deeplinking to my app. To be more specific, this also only happens when trying to open a deeplink to my app from Facebook Messenger with chat heads active.

Sometimes, when trying to return(not open, just return after messenger has overlayed app) to my app(which has only one activity) using a deeplink from FBMessenger the activity gets recreated. onCreate method is called and a new instance of my activity is being created. The main problem is that this does not happen after the old activity is destroyed, I've added logs and first new activity's onCreate gets called, and only after that old activity's onDestroy gets called.

So why does Android try to create a new instance of my activity if it hasn't destroyed the old one yet?

Activity's launchMode is set to singleTask.

Edit: Also tried with launchMode set to singleInstance or singleTop.

Edit 2: Found possible fix by adding android:documentLaunchMode="intoExisting" to activity. Will do a few more tests tomorrow morning and post this fix as solution if everything works fine.

Boby
  • 856
  • 7
  • 9

1 Answers1

2

Use this in your Android manifest

 android:documentLaunchMode="intoExisting"
  • Check https://developer.android.com/guide/topics/manifest/activity-element.html for more info – Ekundayo Blessing Funminiyi Jul 20 '17 at 07:46
  • Hi, thanks for your fast answer but it doesn't work. Same behaviour. I'll update my question. – Boby Jul 20 '17 at 07:47
  • I did, but couldn't find any setting that might prevent this behaviour. – Boby Jul 20 '17 at 08:03
  • Check this : https://stackoverflow.com/questions/4341600/how-to-prevent-multiple-instances-of-an-activity-when-it-is-launched-with-differ/ – Ekundayo Blessing Funminiyi Jul 20 '17 at 08:33
  • Something like that might work, will try and let you know how it goes. – Boby Jul 20 '17 at 08:45
  • That didn't work, it crashes the app. Also, one other interesting fact is that my activity's onNewIntent never gets called. – Boby Jul 20 '17 at 09:46
  • It's default Branch.io sdk implementation. I just managed to find a possible fix by adding android:documentLaunchMode="intoExisting" to activity. It seems to work, but I still want to do a few tests tomorrow morning and if it turns out to be the solution I'll let you know. Thank you very much for your time and sugestions. – Boby Jul 20 '17 at 14:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/149728/discussion-between-ekundayo-blessing-funminiyi-and-boby). – Ekundayo Blessing Funminiyi Jul 20 '17 at 14:11