我跟隨tutorial瞭解如何爲移動設備構建後端,並且能夠爲我的Android應用程序創建後端並在GAE上存儲Entites。問題是,知道如何找回我用下面的代碼我entity.To店的entites的屬性:從Google App Engine後臺檢索實體到Android應用程序
public class EndpointsTask extends AsyncTask<Context, Integer, Long> {
protected Long doInBackground(Context... contexts) {
Userendpoint.Builder endpointBuilder = new Userendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(),
new HttpRequestInitializer() {
public void initialize(HttpRequest httpRequest) { }
});
Userendpoint endpoint = CloudEndpointUtils.updateBuilder(
endpointBuilder).build();
try {
User user = new User();
String username;
if (responseCheckbox.isChecked()) {
username = MainActivity.getPersonName();
}
else {
username = usernameTextField.getText().toString();
}
String location = locationTextField.getText().toString();
String tempAge = ageTextField.getText().toString();
String tempWeight = weightTextField.getText().toString();
String gender = genderTextField.getText().toString();
String occupation = occupationTextField.getText().toString();
int age = Integer.parseInt(tempAge);
int weight = Integer.parseInt(tempWeight);
user.setUsername(username);
user.setLocation(location);
user.setAge(age);
user.setWeight(weight);
user.setGender(gender);
user.setOccupation(occupation);
@SuppressWarnings("unused")
User result;
result = endpoint.insertUser(user).execute();
} catch (IOException e) {
e.printStackTrace();
}
return (long) 0;
}
}
在我onCreate()
方法new EndpointsTask().execute(getApplicationContext());
的調用。
存取實體的屬性,並顯示它們使用TextViews
這是我曾嘗試:
public class EndpointsTask extends AsyncTask<Context, Integer, Long> {
protected Long doInBackground(Context... contexts) {
Userendpoint.Builder endpointBuilder = new Userendpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(),
new HttpRequestInitializer() {
public void initialize(HttpRequest httpRequest) { }
});
Userendpoint endpoint = CloudEndpointUtils.updateBuilder(
endpointBuilder).build();
try {
User user = new User();
usernameTextView.setText(user.getUsername());
locationTextView.setText(user.getLocation());
ageTextView.setText(user.getAge());
occupationTextView.setText(user.getOccupation());
weightTextView.setText(user.getWeight());
genderTextView.setText(user.getGender());
User result = endpoint.getUser(user.getUsername()).execute();
} catch (Exception e) {
e.printStackTrace();
}
return (long) 0;
}}
,然後在我的onCreate()
method.When叫new EndpointsTask().execute(getApplicationContext());
我試圖運行應用程序,我不沒有任何東西。 我花了幾個小時尋找如何做到這一點,但我只找到保存實體的教程。 任何幫助,將不勝感激。
您可以發佈您的用戶實體源代碼嗎? – Gomino
還你的Userendpoint getUser方法 – Gomino
@gomino請找到這兩個[這裏](https://gist.github.com/JudeOchalifu/9128082) –