How to use the Google App Engine as a backend data

2019-03-16 02:49发布

I'm actually a beginner in android and needs a lot of help. I have made an app with embedded database and now want to put it onto some dynamic location. Have simple form of data (some addresses and branch information etc). I actually have no idea about how to use a dynamic server placed on dynamic location.

How can I do this? Please guide me stepwise

I browsed and found some terms like "write Service", "Close/open back-ends" etc. Kindly do guide me. Another question that I have is: do I need some kind of registration, api-key or any other thing. I just added the "google plugins" for eclipse and I can create App engine connected with Android App

1条回答
孤傲高冷的网名
2楼-- · 2019-03-16 03:33

Yes you do need a key. Look at this http://developer.android.com/google/gcm/gs.html

First, we need to send data to/from the client for the example you set up (App engine connected with Android App) using

com.google.android.gcm.server.Sender helper class

Again, that helper class is step #4 and how to use it is in Writing the Server-side Application Server-side Application

Naturally then you want to persist or look up data. You can do that in the whatever class is used to send/receive messages (which of course uses the Sender helper class above)

Then the easiest and maybe best way for AppEngine if you are using Java is to use Objectify. Trust me or google it to see how good it is. https://code.google.com/p/objectify-appengine/

The docs for Objectify are really good and I didn't really have any trouble the first times.

Their simple example is:

@Entity
class Car {
    @Id String vin; // Can be Long, long, or String
    String color;
}

ofy().save().entity(new Car("123123", "red")).now();
Car c = ofy().load().type(Car.class).id("123123").get();
ofy().delete().entity(c);

I think you are good to go.

Summary:

  • YourMessageClass (on Appengine)

    -- uses com.google.android.gcm.server.Sender to send/recieve data

    -- uses Objectify to persist data.

The next question is where are you putting YourMessageClass. Will it be in a Servlet that is handling a short-lived request? (https://developers.google.com/appengine/docs/java/runtime#Requests_and_Servlets) Will it be in a long-running backend? (https://developers.google.com/appengine/docs/java/backends/) but that is beyond the scope of this discussion.

查看更多
登录 后发表回答