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
The to getter methods you mentioned are wrapped into properties in Xamarin. So you have to override the properties.
This code works for me:
`
public override Intent ParentActivityIntent { get { return GetParentActivityIntent(); } } public override Intent SupportParentActivityIntent { get { return GetParentActivityIntent(); } } private Intent GetParentActivityIntent() { // your code here }
`
Answers
The to getter methods you mentioned are wrapped into properties in Xamarin. So you have to override the properties.
This code works for me:
`
`
Worked perfect. Thank you!