OnActivity在同一活动中执行两次

时间:2018-12-04 10:45:47

标签: android kotlin facebook-android-sdk

我试图以几种方式运行它,但是callbackManager调用了两次,并且仅在登录时调用。当我再次按fb_login_button(用于注销)时,它仅执行一次 。吐司用来在屏幕上显示它,但是它们都显示相同的东西(执行两次)。

fb_login_button.setOnClickListener({
        callbackManager = CallbackManager.Factory.create()
        LoginManager.getInstance().logInWithReadPermissions(this, arrayListOf("public_profile","email"))
        LoginManager.getInstance().registerCallback(callbackManager,
            object : FacebookCallback<LoginResult>{
                override fun onSuccess(result: LoginResult?) {                    
Toast.makeText(this@SignIN,"Success",Toast.LENGTH_LONG).show()
                    Log.d("ss",":'(")
                }

                override fun onCancel() {
                    Toast.makeText(this@SignIN,"Cancelled Facebook",Toast.LENGTH_LONG).show()
                }

                override fun onError(error: FacebookException?) {
                    Toast.makeText(this@SignIN,"Error Facebook",Toast.LENGTH_LONG).show()
                }
            })
    })
}    
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    callbackManager?.onActivityResult(requestCode, resultCode, data)
}

搜索alt后,我收到了一些有关同一问题但活动不同的帖子。 onActivityResult executing twice onViewCreated called twice OnActivityResult getting called twice in Android onActivityResult called twice

0 个答案:

没有答案