diff --git a/.gitignore b/.gitignore index d12963ef..ed5c9cf3 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ obj .DS_Store log.txt +.vscode diff --git a/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginActivity.java b/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginActivity.java index 2bdc45ff..21dd2bda 100644 --- a/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginActivity.java +++ b/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginActivity.java @@ -199,6 +199,12 @@ protected void init() { } } + @Override + protected void onDestroy() { + super.onDestroy(); + customTabsHelper.onDestroy(this); + } + protected void loadUrl() { Intent intent = getIntent(); diff --git a/core-android/src/main/java/com/uber/sdk/android/core/utils/CustomTabsHelper.java b/core-android/src/main/java/com/uber/sdk/android/core/utils/CustomTabsHelper.java index 471ba75c..6e808434 100644 --- a/core-android/src/main/java/com/uber/sdk/android/core/utils/CustomTabsHelper.java +++ b/core-android/src/main/java/com/uber/sdk/android/core/utils/CustomTabsHelper.java @@ -51,6 +51,8 @@ public class CustomTabsHelper { private static String packageNameToUse; + private CustomTabsServiceConnection connection; + public CustomTabsHelper() {} /** @@ -69,7 +71,7 @@ public void openCustomTab( final String packageName = getPackageNameToUse(context); if (packageName != null) { - final CustomTabsServiceConnection connection = new CustomTabsServiceConnection() { + connection = new CustomTabsServiceConnection() { @Override public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient client) { client.warmup(0L); // This prevents backgrounding after redirection @@ -78,18 +80,27 @@ public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabs customTabsIntent.intent.setData(uri); customTabsIntent.launchUrl(context, uri); } + @Override - public void onServiceDisconnected(ComponentName name) {} + public void onServiceDisconnected(ComponentName name) { + } }; CustomTabsClient.bindCustomTabsService(context, packageName, connection); } else if (fallback != null) { fallback.openUri(context, uri); } else { - Log.e(UberSdk.UBER_SDK_LOG_TAG, - "Use of openCustomTab without Customtab support or a fallback set"); + Log.e(UberSdk.UBER_SDK_LOG_TAG, "Use of openCustomTab without Customtab support or a fallback set"); } } + /** + * Called to clean up the CustomTab when the parentActivity is destroyed. + */ + public void onDestroy(Activity parentActivity) { + parentActivity.unbindService(connection); + connection = null; + } + /** * Goes through all apps that handle VIEW intents and have a warmup service. Picks * the one chosen by the user if there is one, otherwise makes a best effort to return a