【问题标题】:How to use dispatch actions on android如何在android上使用调度动作
【发布时间】: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


    【解决方案1】:

    您可能需要查看 ADT 的 GAE 插件为“App Engine Connected Android 应用程序”生成的源代码以获取灵感。他们通过使用 Android 的 HttpClient 调用 GWT 端点来做类似的事情。

    https://developers.google.com/eclipse/docs/appengine_connected_android

    【讨论】:

    • 嗨。谢谢,我看过那个项目,但是当与 GWTP 插件集成到 Eclipse 时它不能很好地工作。我只需要一个关于如何将 gwt-platform 插件与 appengine 和 Android 客户端合并的简短示例。你能帮我解决这个问题,或者至少给我一个关于一切流程的提示吗?
    • 使用向导创建一个小型测试项目并查看源代码。它可能不适用于您的项目,但您将了解如何实现 Android 方面的东西。
    • @NikolayElenkov 你想为客户端创建安卓应用吗?或使用相同的应用程序,但使用 android webview 功能兼容移动设备?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 2018-03-13
    • 1970-01-01
    相关资源
    最近更新 更多