使用谷歌Android的加设计:怎样才能再次GoogleApiClient.connect? [英] Android design using Google Plus: How do I GoogleApiClient.connect again?

查看:442
本文介绍了使用谷歌Android的加设计:怎样才能再次GoogleApiClient.connect?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一大堆的活动。的流程如下:

So, I have a bunch of activities. The flow is as follows:


  1. 主要活动:我连接到谷歌加帐户在这里,然后调用显示日志,从谷歌帐户获取数据

  1. Main Activity: I connect to Google Plus account here, then call Show Logs, to get data from Google account.

我也有关于和设置活动。
现在,如果我去公司,然后回来日志,Android的抛出错误GoogleApiClient未连接。所以,我要再次呼吁在MainActivity用于连接其他我应该把所有的连接code到公共或基本活动的。

I also have About and Setting activities. Now if I go to About then come back to Logs, Android throws error that GoogleApiClient is not connected. So should I again call the MainActivity for connecting else should I move all of the connection code to Common or Base Activity.

我很抱歉,如果我不太清楚。

I am sorry if I am not clear enough.

推荐答案

如果该GoogleApiClient在主要活动实例化,一旦离开该活动将断开连接。

If the GoogleApiClient is instantiated in the Main activity, once you leave that activity it will disconnect.

有关你的目的,你可以尝试在整个活动具有GoogleApiClient的多个实例(可能是低效的),但谷歌的界面将不会要求用户多次为每个活动签名。每个实例将访问相同的状态。
您可以检查此职位的详细信息
<一href=\"http://stackoverflow.com/questions/16827839/access-google-plus-client-from-multiple-activities\">Access谷歌加上从多个活动客户

For your purposes you can try having multiple instances of the GoogleApiClient across your activities (might be inefficient) but Google's interface will not require the user to sign in multiple times for each activity. Each instance will access the same state. You can check this post for more info Access google plus client from multiple activities

或者已经尝试实现在AsyncTask的,将保持在后台运行的连接。
看看这个链接
http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html

Or have try to implement the connection in an AsyncTask that will keep running in the background. Have a look at this link http://www.androiddesignpatterns.com/2013/04/retaining-objects-across-config-changes.html

这篇关于使用谷歌Android的加设计:怎样才能再次GoogleApiClient.connect?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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