在Android上,当用户取消时不会调用AWSMobileClient.showSignIn回调

时间:2019-03-21 17:41:48

标签: android aws-sdk aws-appsync aws-amplify

我正在使用Amazon随附的Sign In UI,该UI会完美地加载和显示,但是当用户按下backpress并返回到调用活动时,无论是成功还是错误,都不会调用该回调,并且随后对showSignIn的调用都会被调用没有效果-没有日志语句或UI。同样,当然,不会调用用户状态侦听器。

这是我主要活动的操作按钮上的调用代码和回调:

2019-03-21 10:30:32.379 D/MainActivity: onStart
2019-03-21 10:30:32.454 I/AWSKeyValueStore: Detected Android API Level = 25
2019-03-21 10:30:32.454 I/AWSKeyValueStore: Using keyAlias = com.amazonaws.mobile.client.aesKeyStoreAlias
2019-03-21 10:30:32.527 I/AWSKeyValueStore: Creating the AWSKeyValueStore with key for sharedPreferences = com.amazonaws.mobile.client
2019-03-21 10:30:32.542 I/AWSKeyValueStore: Detected Android API Level = 25
2019-03-21 10:30:32.546 I/AWSKeyValueStore: Using keyAlias = com.amazonaws.android.auth.aesKeyStoreAlias
2019-03-21 10:30:32.571 I/AWSKeyValueStore: Creating the AWSKeyValueStore with key for sharedPreferences = com.amazonaws.android.auth
2019-03-21 10:30:32.571 D/AWSMobileClient: Using the SignInProviderConfig from `awsconfiguration.json`.
2019-03-21 10:30:32.576 D/OpenGLRenderer: HWUI GL Pipeline
2019-03-21 10:30:32.647 D/AppSyncOfflineMutationManager: Thread:[319]: Internet CONNECTED.
2019-03-21 10:30:32.707 I/AWSKeyValueStore: Detected Android API Level = 25
2019-03-21 10:30:32.707 I/AWSKeyValueStore: Using keyAlias = com.amazonaws.android.auth.aesKeyStoreAlias
2019-03-21 10:30:32.711 I/OpenGLRenderer: Initialized EGL, version 1.4
2019-03-21 10:30:32.711 D/OpenGLRenderer: Swap behavior 1
2019-03-21 10:30:32.711 W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
2019-03-21 10:30:32.711 D/OpenGLRenderer: Swap behavior 0
2019-03-21 10:30:32.719 D/EGL_emulation: eglCreateContext: 0x9e205780: maj 3 min 0 rcv 3
2019-03-21 10:30:32.720 D/EGL_emulation: eglMakeCurrent: 0x9e205780: ver 3 0 (tinfo 0x9c0fe150)
2019-03-21 10:30:32.721 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf
2019-03-21 10:30:32.721 E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
2019-03-21 10:30:32.721 I/AWSKeyValueStore: Creating the AWSKeyValueStore with key for sharedPreferences = com.amazonaws.android.auth
2019-03-21 10:30:32.722 D/CognitoCachingCredentialsProvider: Loading credentials from SharedPreferences
2019-03-21 10:30:32.722 D/CognitoCachingCredentialsProvider: No valid credentials found in SharedPreferences
2019-03-21 10:30:32.775 I/AWSKeyValueStore: Detected Android API Level = 25
2019-03-21 10:30:32.775 I/AWSKeyValueStore: Using keyAlias = CognitoIdentityProviderCache.aesKeyStoreAlias
2019-03-21 10:30:32.794 I/AWSKeyValueStore: Creating the AWSKeyValueStore with key for sharedPreferences = CognitoIdentityProviderCache
2019-03-21 10:30:32.811 D/AWSMobileClient: Inspecting user state details
2019-03-21 10:30:32.811 D/UserStateCB: success
2019-03-21 10:30:32.816 I/userState: user is signed out
2019-03-21 10:30:32.954 W/android.hardware.graphics.mapper@2.0::Mapper: getService: found null hwbinder interface
2019-03-21 10:30:33.105 D/EGL_emulation: eglMakeCurrent: 0x9e205780: ver 3 0 (tinfo 0x9c0fe150)
2019-03-21 10:30:33.600 I/Choreographer: Skipped 35 frames!  The application may be doing too much work on its main thread.
2019-03-21 10:30:40.870 D/MainActivity: fab click
2019-03-21 10:30:40.871 D/AWSMobileClient: Inspecting user state details
2019-03-21 10:30:40.883 D/AWSMobileClient: Retrieving the client instance for class: class com.amazonaws.mobile.auth.ui.SignInUI
2019-03-21 10:30:40.883 D/SignInUI: Initializing SignInUI.
2019-03-21 10:30:40.883 D/AWSMobileClient: Created the new client: com.amazonaws.mobile.auth.ui.SignInUI@1b9029d
2019-03-21 10:30:40.887 D/SignInUI: Initiating the SignIn flow.
2019-03-21 10:30:40.887 D/SignInUI: User is not signed-in. Presenting the SignInUI.
2019-03-21 10:30:40.887 D/SignInUI: Presenting the SignIn UI.
2019-03-21 10:30:40.888 D/CognitoUserPoolsSignInProvider: Initializing Cognito User Pools
2019-03-21 10:30:40.889 I/AWSKeyValueStore: Detected Android API Level = 25
2019-03-21 10:30:40.889 I/AWSKeyValueStore: Using keyAlias = CognitoIdentityProviderCache.aesKeyStoreAlias
2019-03-21 10:30:40.898 I/AWSKeyValueStore: Creating the AWSKeyValueStore with key for sharedPreferences = CognitoIdentityProviderCache
2019-03-21 10:30:41.200 D/SignInView: Using defaults: backgroundColor = -12303292; logoResId = 2131165277
2019-03-21 10:30:41.200 D/SignInView: Background Color : -12303292
2019-03-21 10:30:41.200 D/SignInView: Logo : 2131165277
2019-03-21 10:30:41.228 D/SignInView: Trying to create an instance of UserPoolSignInView
2019-03-21 10:30:41.323 D/SignInView: Skipping creating the SignInButtons. No SignInbuttons were added to the view.
2019-03-21 10:30:41.415 I/zygote: Do partial code cache collection, code=25KB, data=28KB
2019-03-21 10:30:41.416 I/zygote: After code cache collection, code=25KB, data=28KB
2019-03-21 10:30:41.416 I/zygote: Increasing code cache capacity to 128KB
2019-03-21 10:30:41.419 I/zygote: Do partial code cache collection, code=25KB, data=45KB
2019-03-21 10:30:41.419 I/zygote: After code cache collection, code=25KB, data=45KB
2019-03-21 10:30:41.419 I/zygote: Increasing code cache capacity to 256KB
2019-03-21 10:30:41.422 I/zygote: JIT allocated 72KB for compiled code of void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
2019-03-21 10:30:41.422 I/zygote: Compiler allocated 4MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
2019-03-21 10:30:41.717 I/zygote: Do full code cache collection, code=122KB, data=72KB
2019-03-21 10:30:41.719 I/zygote: After code cache collection, code=116KB, data=51KB
2019-03-21 10:30:41.733 D/EGL_emulation: eglMakeCurrent: 0x9e205780: ver 3 0 (tinfo 0x9c0fe150)
2019-03-21 10:30:41.818 D/EGL_emulation: eglMakeCurrent: 0x9e205780: ver 3 0 (tinfo 0x9c0fe150)
2019-03-21 10:30:41.917 D/EGL_emulation: eglMakeCurrent: 0x9e205780: ver 3 0 (tinfo 0x9c0fe150)
2019-03-21 10:30:43.752 D/MainActivity: onStart
2019-03-21 10:30:43.830 D/EGL_emulation: eglMakeCurrent: 0x9e205780: ver 3 0 (tinfo 0x9c0fe150)
2019-03-21 10:30:46.439 D/MainActivity: fab click
2019-03-21 10:30:49.144 D/MainActivity: fab click

以下是有关onStart,第一次单击和UI显示,取消以及随后两次单击的日志:

regex=True

我尝试将releaseSignInWait和signOut添加到onStart(如果已初始化AWSMobileClient),甚至尝试在onStart中重新初始化,但这没有任何区别。

那么,如何确定是否以及何时调用releaseSignInWait?我还需要做其他事情来刷新移动客户端的状态,以便showSignIn可以再次工作吗?我做错了吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

在您的authenticationActivity中,您想拥有一个UserStateListener,如下所示:

AWSMobileClient.getInstance().addUserStateListener(new UserStateListener() {
            @Override
            public void onUserStateChanged(UserStateDetails userStateDetails) {
                switch (userStateDetails.getUserState()){
                    case GUEST:
                        Log.i("userState", "user is in guest mode");
                        break;
                    case SIGNED_OUT:
                        //This is the case that most likely interest you
                        //showSignIn() calls the the builder for displaying the sign in form 
                        Log.i("userState", "user is signed out");
                        showSignIn();
                        break;
                    case SIGNED_IN:
                        Log.i("userState", "user is signed in");
                        break;
                    case SIGNED_OUT_USER_POOLS_TOKENS_INVALID:
                        Log.i("userState", "need to login again");
                        break;
                    case SIGNED_OUT_FEDERATED_TOKENS_INVALID:
                        Log.i("userState", "user logged in via federation, but currently needs new tokens");
                        break;
                    default:
                        Log.e("userState", "unsupported");
                }
            }
        }); 

(我添加了所有可能的情况,但您很可能会使用SIGNED_OUT一种情况。)

然后,您可以通过简单的AWSMobileClient.getInstance().signOut()

在任何您喜欢的活动中提供注销选项。