我想将JSONObject传递给下面代码中else部分中的另一个活动,这样我就可以在其他活动中使用配置文件详细信息,
public void redirectToActivity(JSONObject result, JSONObject profile){
try {
String status = result.getString("status");
if (status.equals("204")) {
Intent intent = new Intent(this, ActivityMenu.class);
intent.putExtra("user", "email");
this.startActivity(intent);
}
else {
Intent intent = new Intent(this, RegisterActivity.class);
this.startActivity(intent);
//here I want to pass JSONObject profile to RegisterActivity
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
通过JSONObject你可以使用一个String.例如:
Intent intent = new Intent(this, RegisterActivity.class);
intent.putExtra("profile", profile.toString());
intent.putExtra("result", result.toString());
this.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
toString()实施JSONObject,类rncodes对象作为紧凑JSON字符串.在你的RegisterActivity,检索字符串:
String profile = getIntent().getStringExtra("profile");
JSONObject profileJSON = new JSONObject(profile)
Run Code Online (Sandbox Code Playgroud)