Forum Xamarin.Android

How to manage up navigation, multiple parents? getParentActivityIntent?

KyleRobitailleKyleRobitaille USUniversity ✭✭

Hi all,

I'm working on converting an Android application over to a Xamarin Android application to vet out the technology, as well as to look into how we might be able to move some of our existing code around to share some code between IOS and Windows instances in the future.

Anyways, I've run into an issue of being able to override getParentActivityIntent and getSupportParentActivityIntent in my Activity to be able to manage the up navigation between activities. The reason I had done it this way was because the specific activity I'm managing has two possible parents that could get to it, and I want to ensure the up navigation returns to the correct parent. I had been doing it by overriding the above functions in my android app, but unfortunately that doesn't seem to be working in Xamarin. I don't seem to be hitting either of the functions. Below is code:

`[Android.Runtime.Register("getSupportParentActivityIntent", "()Landroid/content/Intent;", "GetGetSupportParentActivityIntentHandler")]
public virtual Intent SupportParentActivityIntent() {
Intent parentIntent = Intent;
Intent newIntent=null;
try {
//you need to define the class with package name
newIntent = new Intent(this,parentIntent.Class);
string test = "test";

        } catch (Exception e) {
            var test = "test";
        }
        return newIntent;
    }

    [Android.Runtime.Register("getParentActivityIntent", "()Landroid/content/Intent;", "GetGetParentActivityIntentHandler")]
    public virtual Intent ParentActivityIntent() {
        Intent parentIntent = Intent;
        Intent newIntent=null;
        try {
            //you need to define the class with package name
            newIntent = new Intent(this,parentIntent.Class);

        } catch (Exception e) {
            var test = "test";
        }
        return newIntent;
    }`

Is there a better way to do this or am i missing something in here?

Thanks

Best Answer

Answers

  • KyleRobitailleKyleRobitaille USUniversity ✭✭

    Worked perfect. Thank you!

Sign In or Register to comment.