【问题标题】:How to fix "Activity has leaked ServiceConnection net.openid.appauth.browser.CustomTabManager$1@41fb56d0 that was originally bound here" error如何修复“活动已泄露 ServiceConnection net.openid.appauth.browser.CustomTabManager$1@41fb56d0 最初绑定在这里”错误
【发布时间】:2019-06-03 09:15:05
【问题描述】:

我正在设置我的 android 应用程序以使用身份验证,并且我正在关注关于 AppAuth for Android 的文档。到目前为止,我已经能够连接身份服务器并向身份服务器发出请求,并返回包含我在请求中发送的大部分数据等的响应。我应该用我的代码交换访问令牌。这是我的问题。我实际上是在复制并粘贴 github 页面上的代码,https://github.com/openid/AppAuth-Android,但它却因上述错误而崩溃。我对 android 比较陌生,这是我在这里的第一个问题,如果我没有很好地提出我的问题,请放轻松。谢谢。

Android Studio 说导致此错误的代码是“authService.performTokenRequest()”。我环顾四周,有些人通过在“onDestroy()”中调用“authService.dispose()”解决了这个问题,但这也因“执行 doInBackground() 时发生错误”而崩溃。以下是导致错误的代码。

authService.performTokenRequest(
    resp.createTokenExchangeRequest(),
    new AuthorizationService.TokenResponseCallback() {
      @Override public void onTokenRequestCompleted(
            TokenResponse resp, AuthorizationException ex) {
          if (resp != null) {
            // exchange succeeded
          } else {
            // authorization failed, check ex for more details
          }
        }
    });

在我的“onCreate()”中我是这样称呼它的。

AuthorizationResponse resp = AuthorizationResponse.fromIntent(getIntent());
        AuthorizationException ex = AuthorizationException.fromIntent(getIntent());
        authState = new AuthState(resp, ex);
        authorizationService = new AuthorizationService(this);
        authorizationService.performTokenRequest(
                resp.createTokenExchangeRequest(),
                new AuthorizationService.TokenResponseCallback() {
                    @Override public void onTokenRequestCompleted(
                            TokenResponse resp, AuthorizationException ex) {
                        authState.update(resp, ex);
                        if (resp != null) {
                            // exchange succeeded
                            Log.e("authstate",authState.getAccessToken());
                        } else {
                            // authorization failed, check ex for more details
                        }
                    }
                });

【问题讨论】:

  • 任何时候你发布一个问题并且你有错误日志。总是,总是发布错误日志。错误日志通常比导致它们的代码更重要。没有他们真的无法看到这里发生了什么。

标签: android identityserver4 appauth


【解决方案1】:

您可以在 onDestroy() 上处理您的 authService。 例如你有

AuthorizationService mAuthService = new AuthorizationService(context);

@Override
protected void onDestroy() {
        mAuthService.dispose();
        mAuthService = null;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多