本文介绍了连接到GoogleApiClient后GoogleApiClient.ConnectionCallbacks方法不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code被连接到GoogleApiClient但onConnected不会被调用。

I've got some code which is connecting to the GoogleApiClient but onConnected is not being called.

public class MainActivity extends Activity implements  GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
    private GoogleApiClient mApiClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initGoogleApiClient();
    }

    private void initGoogleApiClient() {
        mApiClient = new GoogleApiClient.Builder( this )
                .addApi( Wearable.API )
                .build();
        mApiClient.connect(); // On completion onConnected() will be called
    }
    @Override
    public void onConnected(Bundle bundle) {
    }

    @Override
    public void onConnectionSuspended(int i) {
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mApiClient.disconnect();
    }

    @Override
    public void onConnectionFailed(com.google.android.gms.common.ConnectionResult connectionResult) {
    }

四大@覆盖方法都不是被称为,这是为什么?

None of the four @Override methods are being called, why is that?

推荐答案

您需要调用addConnectionCallbacks()和addOnConnectionFailedListener()在 GoogleApiClient.Builder

mApiClient = new GoogleApiClient.Builder( this )
    .addApi( Wearable.API )
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this)
    .build();

这篇关于连接到GoogleApiClient后GoogleApiClient.ConnectionCallbacks方法不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 09:27