In my recent programmed Android App, I discovered a problem regarding Chrome Custom Tabs. I'm using Custom Tabs to open sites of different Social Media Platforms like Twitter, Twitch, YouTube, Instagram, Snapchat and Facebook.
I'm going to give you a quick overview of the Activities of my app so you can understand my problem:
DashboardActivity -> PostActivity -> opens Custom Tabs
When I use Custom Tabs to open a Twitter Page and I click on the Close-Button in the top I will be redirected to the PostActivity. This also happens on Twitter, YouTube, and the other platforms.
But when I open a Facebook page using Custom Tabs and I close the Tab I'm redirected to the DashboardActivity despite I use the same piece of code to start it as to start the other pages.
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
switch (view.getId()) {
case R.id.youtube_content_image: {
//START YOUTUBE APP
YouTubePost youtubePost = (YouTubePost) mPosts.get(position);
String url = "http://www.youtube.com/watch?v=" + youtubePost.getId();
builder.setToolbarColor(ContextCompat.getColor(getApplicationContext(), R.color.color_youtube));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
}
case R.id.instagram_content_image: {
InstagramPost post = (InstagramPost) mPosts.get(position);
builder.setToolbarColor(ContextCompat.getColor(getApplicationContext(), R.color.color_instagram));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(post.getWebLink()));
}
case R.id.snapchat_content_text: {
SnapchatPost post = (SnapchatPost) mPosts.get(position);
builder.setToolbarColor(ContextCompat.getColor(getApplicationContext(), R.color.color_snapchat));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(post.getSnapchatUrl()));
}
case R.id.facebook_content_text: {
FacebookPost post = (FacebookPost) mPosts.get(position);
String url = "https://www.facebook.com/" + post.getId();
builder.setToolbarColor(ContextCompat.getColor(getApplicationContext(), R.color.color_facebook));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
}
case R.id.twitter_content_text: {
TwitterPost post = (TwitterPost) mPosts.get(position);
String url = "https://twitter.com/" + mAccountHolder.getTwitterUsername() +"/status/" + post.getId();
builder.setToolbarColor(ContextCompat.getColor(getApplicationContext(), R.color.color_twitter));
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
}
}