Skip to content

Commit

Permalink
Merge pull request #176 from uber/fix_service_connection
Browse files Browse the repository at this point in the history
Fix service connection
  • Loading branch information
tyvsmith authored Nov 23, 2019
2 parents 06e43f6 + 7a70a1a commit 78226a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ obj

.DS_Store
log.txt
.vscode
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ protected void init() {
}
}

@Override
protected void onDestroy() {
super.onDestroy();
customTabsHelper.onDestroy(this);
}

protected void loadUrl() {
Intent intent = getIntent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class CustomTabsHelper {

private static String packageNameToUse;

private CustomTabsServiceConnection connection;

public CustomTabsHelper() {}

/**
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 78226a6

Please sign in to comment.