简体   繁体   English

如何在不同的活动中访问GoogleApiClient

[英]How do i Access GoogleApiClient in Different Activities

如何在不同的活动中访问Googleapiclient?如何使其全局化以便可以在所有活动中使用?我们可以通过意图传递它吗?

No, you can't pass it via intent. 不,您无法通过意图传递它。 If it needs to be used across activities you either need to make a new one for each Activity or you need to make it owned by a Service that the activities then query for results. 如果需要在活动之间使用它,则需要为每个活动创建一个新活动,或者需要将其设置为服务所拥有,然后由服务查询结果。

You could use an application class. 您可以使用应用程序类。 Its a singelton based class which you can access from almost everywhere. 它是基于singelton的类,您几乎可以在任何地方访问。

Documentation for application class : https://developer.android.com/reference/android/app/Application.html 应用程序类的文档: https : //developer.android.com/reference/android/app/Application.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM