【发布时间】:2012-06-24 12:06:27
【问题描述】:
我正在开发一个托管在 AppEngine 上的项目,对于浏览器客户端,我使用的是 GWTP 平台,这意味着在服务器上使用 GIN(在客户端)和 GUICE。此外,它还使用模型、演示者、动作和事件。
我也在考虑为该服务编写一个 android 客户端,但我不知道如何开始,因为我不知道如何与 web 服务连接和交换数据。我将不得不使用用于浏览器客户端的操作和操作处理程序 (http://code.google.com/p/gwt-platform/wiki/GettingStartedDispatch)。从Android我只知道如何使用RPC,我无法建立连接,我不知道如何将类从设备映射到服务器。
例如,通过使用 GWTP,如果在浏览器客户端上我想在服务器上做某事,我会实现一个 Action 类、一个 ActionResult 类(都在客户端上)和一个 ActionHandler 类(在服务器上)。为了调度一个动作,我使用 DispatchAsync 接口并使用 AsyncCallback 来获取结果。
动作(在客户端) - SendRoadNotification.java :
public class SendRoadNotification extends
ActionImpl<SendRoadNotificationResult> {
private RoadNotification roadNot;
@SuppressWarnings("unused")
private SendRoadNotification() {
// For serialization only
}
public SendRoadNotification(RoadNotification roadNot) {
this.roadNot = roadNot;
}
public RoadNotification getRoadNot() {
return roadNot;
}
}
ActionResult (在客户端) -- SendRoadNotfifcationResult.java :
public class SendRoadNotificationResult implements Result {
private RoadNotification roadNot;
@SuppressWarnings("unused")
private SendRoadNotificationResult() {
// For serialization only
}
public SendRoadNotificationResult(RoadNotification roadNot) {
this.roadNot = roadNot;
}
public RoadNotification getRoadNot() {
return roadNot;
}
}
ActionHandler(在服务器上)——SendRoadNotificationActionHandler.java:
public class SendRoadNotificationActionHandler implements
ActionHandler<SendRoadNotification, SendRoadNotificationResult> {
static DataStore ds = DataStore.getDatastoreService();
@Inject
public SendRoadNotificationActionHandler() {
}
@Override
public SendRoadNotificationResult execute(SendRoadNotification action,
ExecutionContext context) throws ActionException {
//Here I am doing something with that action
}
@Override
public void undo(SendRoadNotification action,
SendRoadNotificationResult result, ExecutionContext context)
throws ActionException {
}
@Override
public Class<SendRoadNotification> getActionType() {
return SendRoadNotification.class;
}
}
我使用这些的方式是:
SendRoadNotification action = new SendRoadNotification(rn);
dispatchAsync.execute(action, sendRoadNotifCallback);
还有回调:
AsyncCallback<SendRoadNotificationResult> sendRoadNotifCallback = new AsyncCallback<SendRoadNotificationResult>() {
@Override
public void onSuccess(SendRoadNotificationResult result) {
}
@Override
public void onFailure(Throwable caught) {
Window.alert("Something went wrong");
}
};
如何在 android 中实现这一点?有人可以给我一个例子或以前有这个问题吗?
我正在使用 AppEngine sdk 1.6.4、GWT sdk 2.4.0、用于 Eclipse 的 GWTP 插件和用于 Eclipse 的 GPE 插件。
【问题讨论】:
标签: android google-app-engine gwt gwt-platform