通过连接对象的其他活动 - 谷歌任务API [英] Pass connection object to other activity - Google Tasks API

查看:137
本文介绍了通过连接对象的其他活动 - 谷歌任务API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎已经达成了墙我这个问题。基本上,我正在它与谷歌的任务API同步您的谷歌任务的应用程序。一切都在我的第一个活动进行得很顺利至今。但现在我想创建一个新的活动,以显示用户的任务列表。因此,要获得我需要在这个新的活动连接对象的任务列表。通常我只给有i.putExtra()或一些变量similiar但ofcourse这不符合(自定义)对象。我已经尝试过使用Parceable和Serializable接口上有包裹在它的对象一个定制类,但我一直在如何类(从谷歌API)本身并没有实现这些收到错误信息。它也不可能通过的参数,因为他们是从谷歌themselfs自定义对象创建类的新实例。有没有人有一个想法或经验,用这个?

I seem to have struck a wall with this problem of mine. Basically i'm working on an app which syncs your google tasks with the Google Tasks API. Everything is going great so far in my first activity. But now I want to create a new activity to show the users task lists. So to get the tasklists I need the connection object in this new activity. Normally I just give variables with i.putExtra() or something similiar but ofcourse this does not work with (custom) objects. I already tried to use Parceable and Serializable on a custom made class which had the object wrapped in it, but I keep getting errors about how the class (from Google API) itself does not implement these. It's also impossible to pass the parameters for creating a new instance of the class because they are themselfs custom objects from Google. Does anyone have an idea or experience with this?

这是在服务对象我需要传递给新的活动:

It's the service object I need to pass to a new activity:

final HttpTransport httpTransport = AndroidHttp.newCompatibleTransport();
final JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
credential = GoogleAccountCredential.usingOAuth2(this, Collections.singleton(TasksScopes.TASKS));
credential.setSelectedAccountName(settings.getString(PREF_ACCOUNT_NAME, null));
// Tasks Client
service = new com.google.api.services.tasks.Tasks.Builder(httpTransport, jsonFactory, credential).setApplicationName("Test").build();

在此先感谢!

推荐答案

林不知道如果是这样做(特别是因为我不知道这个任务服务类)的最佳方式,但来到了我的一个想法其是在扩展应用程序类定义的变量。这是一个文章描述应用程序类和说明类的创造,延伸它来管理一些全球数据

Im not sure if it is the best way to do it (specially because I do not know this task service class), but one idea that came to my mind was of having the variable defined in a class that extends the Application. Here it is an article describing the Application class and illustrating the creation of class that extends it to manage some "global data"

在这种方式,您可以设置/得到它在不同的活动。

In that way, you can set/get it in the different activities.

这篇关于通过连接对象的其他活动 - 谷歌任务API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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