应用程序在googleApiClient.connect()上崩溃; [英] App crashes on googleApiClient.connect();

查看:123
本文介绍了应用程序在googleApiClient.connect()上崩溃;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用,我想添加Google Play成就.我遵循了这一点:

I have an app, and I want to add Google Play achievements. I followed this:

https://developers.google.com/games/services/android/init

我的清单上有这个(带有正确的ID):

I have this at my manifest (with the right ID):

<meta-data android:name="com.google.android.gms.appstate.APP_ID"
    android:value="000000000000" />
<meta-data android:name="com.google.android.gms.games.APP_ID"
    android:value="000000000000" />

我有这个OnStart:

I have this OnStart:

    @Override
protected void onStart() {
    try
    {
        super.onStart();
        googleApiClient.connect();
    }catch (Exception e)
    {
        Exception error;
        error = e;
    }
}

通过调试,当执行".connect()"时,它会崩溃,并且"TRY CATCH"不会检测到它. 这是我的"OnCreate()".

With debuging, when the ".connect()" is executed, it crashes, and "TRY CATCH" doesn´t detect it. This is my "OnCreate()".

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

   googleApiClient =  new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            // add other APIs and scopes here as needed
            .build();
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

    lanzarFragments();
}

这是我的"MainActivity"的声明方式:

This is how my "MainActivity" is declared:

public class MainActivity extends AppCompatActivity implements
    GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener

我的GoogleApiClient的声明如我在此处所示:

My GoogleApiClient, is declared like I show here:

public static  GoogleApiClient googleApiClient;

我要添加的是,方法"lanzarFragments()"启动一个Fragment.我所有的应用程序都是碎片,一个又一个.但是我只有一个活动,即Main,具有我写下的"OnCreate()".

I want to add, that the method "lanzarFragments()", starts a Fragment. All my app is with fragments, changing one by another. But I just have one Activity, the Main, that has the "OnCreate()" I wrote up.

关于崩溃的一些想法以及如何解决?谢谢.

Some Idea about what it crashes and how to fix it? Thank you.

推荐答案

在onStart()中尝试一下:

Try this in onStart():

@Override
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

在onStop();

in onStop();

@Override
protected void onStop() {
    super.onStop();
    mGoogleApiClient.disconnect();
}

这来自官方文档.您不需要为此方法进行try/catch,因此为什么不调用该异常.

This is from Official Docs. You don't need a try / catch for this method hence why the exception is not getting called.

您能否也发布您的logcat,请查看更多详细信息,因为没有它,其他人将无法找到确切的问题.

Could you post your logcat also please to see in more detail as without it others wont be able to find out the exact problem.

这篇关于应用程序在googleApiClient.connect()上崩溃;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆