Error in Fragment: “Already managing a GoogleApiClient with id 0”

后端 未结 10 1951
独厮守ぢ
独厮守ぢ 2020-12-13 08:16

Everything works right the first time, if you launch a second time you see this error:

FATAL EXCEPTION: main
Process         


        
10条回答
  •  爱一瞬间的悲伤
    2020-12-13 08:59

    This works for me to avoid crashing issues using kotlin

    private lateinit var googleApiClient: GoogleApiClient
    

    And then just verify if the variable is already initialized

     if(!::googleApiClient.isInitialized) {
                googleApiClient = GoogleApiClient.Builder(context)
                        .enableAutoManage(activity, this)
                        .addApi(Auth.GOOGLE_SIGN_IN_API, options)
                        .build()
      }
    

提交回复
热议问题