8

How can I mix both pages together

I want to do something platform specific (Android) OnActivityResult but I use a ContentPage in Xamarin.Forms

How do I know in my .Droid project which activity it is?

Lets say I have a page called CalendarPage : ContentPage. Where do I register it in my droid project so I can catch the ActivityResult in that Activity(ContentPage)?

I have no clue since I'm new to Xamarin.Forms and learning it.

5
  • 2
    Xamarin forms runs on one activity (most likely your main activity), so everything will end up in there.
    – Johan
    Oct 23, 2015 at 11:24
  • Pls make it as an aswhere so i can accept it Thanx again m8 :) Oct 23, 2015 at 11:25
  • Can ya check somewhere wich activity is loaded ??? Oct 23, 2015 at 11:27
  • search for global::Xamarin.Forms.Forms.Init(this, bundle);, the this is the activity.
    – Johan
    Oct 23, 2015 at 11:28
  • Ill put up an example now.
    – Johan
    Oct 23, 2015 at 11:29

1 Answer 1

9

Xamarin forms runs on one activity, which is most like your main activity.

There are two sample projects that show you how to communicate between native and form parts of the code, which can be found here

  1. https://github.com/xamarin/xamarin-forms-samples/tree/master/Forms2Native
  2. https://github.com/xamarin/xamarin-forms-samples/tree/master/Native2Forms

However, to answer your question, you would do something like the following

 private const int MyRequestCode = 101;

 //Start activity for result
 var contactPickerIntent = new Intent(Intent.ActionPick, Android.Provider.ContactsContract.Contacts.ContentUri);
 context.StartActivityForResult(contactPickerIntent, MyRequestCode);

and then in your main activity (the activity that initializes your xamarin forms application (using global::Xamarin.Forms.Forms.Init(this, bundle);)

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
    if (requestCode == MyRequestCode && resultCode == Result.Ok)
    {
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.