0

xamarin android project unbindservice for custom tabs. I am not able to find out the method of unbinding services.

Query
  • 625
  • 1
  • 7
  • 22

1 Answers1

0

If you use the Xamarin.Android.Support.CustomTabs library, please notice that CustomTabsActivityManager class didn't provide the UnBindService() method, and you can't get the CustomTabsServiceConnection instance from outside so that it's hard to unbind the service in your Activity.

Solution:

So you need to add the UnBindService() method by yourself, for example:

public class MyCustomTabsActivityManager
{
     CustomTabsServiceConnectionImpl connection;

     public Activity ParentActivity { get; private set; }
     public CustomTabsClient Client { get; private set; }

     CustomTabsSession session = null;

     ...

     public void UnBindService()
     {
         if (connection != null)
         {
             ParentActivity.UnbindService(connection);
             Client = null;
             session = null;
          }
     }
}

Then, you could use this UnBindService() in your Activity:

protected override void OnDestroy()
{
    myCustomTabsActivityManager.UnBindService();
    base.OnDestroy();
}
York Shen
  • 9,014
  • 1
  • 16
  • 40