0

I'm using Xamarin.Android to build an app for a customer that's meant to be supplementary to another app. The idea is that once they reach a point in their workflow where my app steps in, they will click a button inside their app that will launch my app, and will open an activity from my app based on some attached parameters.

My problem is that in the "calling" app, all that's exposed for me to work with is a parameterized URI that's passed directly to Android, so I have no means of creating and passing an Intent object. I can change the URI it sends to be whatever I like, so I've already added an intent filter that looks for the custom scheme myapp://.

I am new to SO, so I apologize if this question has been answered elsewhere, but I have looked for a few hours and in my searches so far, all I've seen are answers related to how to call another app from my own. The question I have is... how do I parse that request on the other end and know not only which activity to open, but the rest of the data or parameters that were in the URI? Is it possible to open an activity based on a parameter in that URI, or can I only point it to one activity?

Thanks in advance!

draconastar
  • 385
  • 3
  • 12
  • Well you can pass the name of the activity, then maintain an enum in your beginning activity and on that basis open the right activity its more than a logical thing than a native implementation – FreakyAli Aug 16 '18 at 08:55
  • What do you mean by "pass the name of the activity"? To where? Sorry if this is a dumb question. – draconastar Aug 16 '18 at 21:45
  • No its not a dumb question i will answer yours wait – FreakyAli Aug 17 '18 at 06:04

1 Answers1

0

What you have to do is quite simple in your URL somewhere pass your activity name that you want to navigate to

Then in your code maintain a enum with all the possible activities you wanna navigate to:

enum ActivityName 
 {
  MainAcitivity,
  SomeotherAcitivity
 }

Then in your received notification get the string where you have given the name of the activity and do something like this :

If(youractivityName==ActivityName.MainActivity.toString())
{
  StartActivity(typeof(MainActivity));
}

Revert in case of queries.

FreakyAli
  • 13,349
  • 3
  • 23
  • 63
  • Thank you for this answer! This has got me opening the activity I need. The only problem is that since I'm performing my check in whatever the base activity is that's opening (in this case my main activity), it opens that activity first, placing it on the stack, then opens the activity that I want. Is there a way to avoid this kind of filtration? – draconastar Aug 22 '18 at 18:09
  • So you don't want that activity in the stack or you want to open that activity directly? – FreakyAli Aug 22 '18 at 20:06
  • Yes, I'd like to avoid having it on the stack. That way, once the activity is finished, the user doesn't then have to back through the opening activity that's on the stack. – draconastar Aug 27 '18 at 15:32
  • Well then do it in your app splash or follow this : https://stackoverflow.com/a/39665485/7462031 – FreakyAli Aug 28 '18 at 05:31