0

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();

Thanks in advance!

4

1 回答 1

2

我不确定这是否是最好的方法(特别是因为我不知道这个任务服务类),但我想到的一个想法是在扩展应用程序的类中定义变量。这是一篇描述 Application 类的文章,并说明了扩展它以管理一些“全局数据”的类的创建

这样,您可以在不同的活动中设置/获取它。

于 2013-11-25T16:46:17.657 回答