将GoogleApiClient obj从一个活动传递给另一个活动 [英] passing the GoogleApiClient obj from one activity to another

查看:145
本文介绍了将GoogleApiClient obj从一个活动传递给另一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在不同于创建GoogleApiClient obj(主要活动)的活动中更新我的排行榜得分。



什么是做这件事的最好方法吗?



使obj可以正确的方式吗?如果是的话,如果这个类是图书馆的一部分,你该怎么做。



你可以让obj变成静态的吗?是否安全?



有关如何实现这一点的任何建议都会很棒。 div>

好吧,我想我会回答我自己的问题,因为我找到了一种当前适合我的方法。
其中大部分来自另一个回答的问题,此处
a>!



这个方法使用basegameutil,所以从Lee的链接回答我可以让我的活动扩展BaseGameActivity并添加所需的方法。



然后,在我的第二个活动中创建一个新的GoogleApiClient实例,然后像这样获取api客户端:

  mGoogleApiClient = getApiClient(); 

我现在可以在我的第二个活动中传递这些信息并根据需要调用方法。



作为Lee States的回答,您可以拥有多个google api客户端实例,并且仍然不会被要求登录每个客户端,因为它知道您已经登录。


I want to be able to update my score for my leaderboard in a different activity other than the one that creates the GoogleApiClient obj ( the main activity ).

What is the best way to do this?

Is making the obj parcelable the correct way? if so how can you do it if the class is part of a library.

Can you make the obj static? is it safe?

Any advice on how to achieve this would be great.

解决方案

Ok I thought i would answer my own Question as i have found a method that currently suits me. Alot of this has come from another answered question found here!

This method uses the basegameutil so going from Lee's answer from the link i can just have both my activities extend the BaseGameActivity and add the required methods.

I then create a new instance of the GoogleApiClient in my second activity and then get the api client like this:

mGoogleApiClient = getApiClient();

i can now pass this around my second activity and call the methods as i wish.

As Lee States in his answer, you can have multiple instances of the google api client and still wont be asked to sign in for each of them as it knows you are already signed in.

这篇关于将GoogleApiClient obj从一个活动传递给另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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