I want to use Chrome custom tabs to properly handle URLs out of my domain. Here is the code
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request){
String url = request.getUrl().toString();
if(url.startWith("http://my.domain.name"))
return false;
else{
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(getResources().getColor(R.color.colorPrimary));
builder.setStartAnimations(getActivity(), R.anim.slide_in_right, R.anim.slide_out_left);
builder.setExitAnimations(getActivity(), R.anim.slide_in_left, R.anim.slide_out_right);
Intent actionIntent = new Intent(
getApplicationContext(), ActionBroadcastReceiver.class);
actionIntent.setData(Uri.parse(url));
PendingIntent menuItemPendingIntent =
PendingIntent.getBroadcast(getApplicationContext(), 0, actionIntent, 0);
builder.addMenuItem(getString(R.string.action_share), menuItemPendingIntent);
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(getActivity(), Uri.parse(url));
return true;
}
}
});
However when I click on the out-of-domain URLs, occasionally I get ANR dialog and UI of the app is freezing.
I try to debug the anr traces but I found no suspect thread. The ANR traces file is quite long, so I posted it here: https://gist.github.com/hoavt-54/42f1109c0619eed81e82a9a8d1128a6d
If you have any suggestion on how to debug the app or how to understand the trace file, I would really appreciate that.