Using an enum contained in a Cloud Endpoint model on a Android client

回眸只為那壹抹淺笑 提交于 2020-02-24 12:06:48

问题


I'm trying to implement an enum in a entity called CargoWrapper. In my android app I'm constructing a CargoWrapper object to send to an endpoint method, and then calling my CargoWrapper setters to set the instance varialbes. One of CargoWrappers instance variables is an enum and it's indexed. The only methods generated for my front end are the setter and getters, I can't see the enum. Does anyone know how to set the enum instance variable from a android client, seems like it should be very straight forward?

https://cloud.google.com/developers/articles/google-cloud-endpoints-for-android/

The documentation says: About Supported Types •Enums. Enums in your backend are generated as String representations in the client code. In other words, if you are making use of the enum functionality in both the backend and client, you will need to define the enum in both places.

An example using the enum in the Android client would be great.


回答1:


The easiest way is to create additional module and include it in other modules.

build.gradle for common module

apply plugin: 'java'

dependencies {
   ...
}

Define your enum in this module. You can choose whatever package you want.

Now include the common module in both Android app and backend modules.

build.gradle for other modules:

dependencies { 
   ... 
   compile project(':common')
}

This way you have only one enum definition (instead of two, in different modules, which have to be manually updated when either of them is changed).



来源:https://stackoverflow.com/questions/28488232/using-an-enum-contained-in-a-cloud-endpoint-model-on-a-android-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!