【发布时间】:2019-09-01 11:24:22
【问题描述】:
我需要将userid 存储在共享首选项中并在第二个活动中使用它,但我不知道该怎么做。我怎样才能只存储id 并在第二个活动中调用它?
这是我的代码:
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Boolean esito = response.getBoolean("Esito");
if (esito) {
JSONArray jsonArray = response.getJSONArray("Dati");
Log.d("JSON", String.valueOf(esito));
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject dato = jsonArray.getJSONObject(i);
String id = dato.getString("id");
String fullname = dato.getString("fullname");
String username = dato.getString("username");
String password = dato.getString("password");
//mTextViewResult.append(id + ", " + fullname + ", " + username + ", " + password + "\n\n");
startActivity(new Intent(getApplicationContext(),LoggedActivity.class));
}
} else {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}
}
}
【问题讨论】:
-
使用 putExtra :)
标签: java android json android-studio sharedpreferences