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

查看:21
本文介绍了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()"方法会启动一个片段.我所有的应用程序都是片段,一个一个地改变.但我只有一个 Activity,即 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天全站免登陆