更新时间:2023-11-14 11:13:52
我还观察到我的 Android 应用程序在服务器端 302 重定向到自定义方案后意外后台,并观察到独立 Chrome 和手动触发的预期处理在客户端重定向.
I've also observed my Android app unexpectedly background after server-side 302 redirection to a custom scheme, and observed expected handling from stand-alone Chrome and manually triggered redirection in the client.
我能够通过调用 预热 功能,然后加载重定向的 url.
I was able to "fix" the issue by calling the warmup function before loading the url that redirects.
换句话说,这是有效的:
In other words, this works:
void launchTab(Context context, Uri uri){
final CustomTabsServiceConnection connection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient client) {
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
final CustomTabsIntent intent = builder.build();
client.warmup(0L); // This prevents backgrounding after redirection
intent.launchUrl(context, uri);
}
@Override
public void onServiceDisconnected(ComponentName name) {}
};
CustomTabsClient.bindCustomTabsService(context, "com.android.chrome", connection);
}
这不起作用:
void launchTab(Context context, Uri uri){
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
final CustomTabsIntent intent = builder.build();
intent.launchUrl(context, uri);
}
Chrome 自定义标签文档 将热身描述为***实践,但它似乎也有助于确保预期的行为.
The Chrome Custom Tab docs describe warming up as a best practice, but it also appears to help ensure expected behavior.
就环境而言,我正在使用 Chrome 51 的 Nexus 5X 进行测试.我在 Gradle 中的 chrome 选项卡依赖项如下所示:
In terms of env, I'm testing on a Nexus 5X w Chrome 51. My chrome tab dependency in Gradle looks like this:
dependencies {
compile 'com.android.support:customtabs:24.0.0'