Saturday, 24 August 2013

Will a reference to the Application context leak my retained fragment?

Will a reference to the Application context leak my retained fragment?

I have a fragment that does some background http calls and because I don't
want the process to be interrupted by configuration changes the fragment
is declared as retainedInstance. Because the service needs to read tokens
from the app's keystore, it needs a reference to a context. So, in the
OnAttach method I grab a reference to the application context from the
hosting activity:
public override void OnAttach(Android.App.Activity activity)
{
base.OnAttach(activity);
appContext = activity.ApplicationContext;
}
I can't reset this reference in OnDestroyView, because the fragment might
still need it.
Will this reference to the Application context leak my fragment?

No comments:

Post a Comment