Passing JSONObject into another activity

后端 未结 7 1951
情歌与酒
情歌与酒 2020-11-30 04:56

I\'m hitting an external API that\'s returning JSON data (new dvd titles). I\'m able to parse out the JSON and list each dvd title and other dvd information into a ListView

7条回答
  •  清歌不尽
    2020-11-30 05:06

    Just create a Parcel like this:

    public class Parcel implements Serializable {
    private JSONObject obj;
    
    public Parcel(JSONObject obj) {
        this.obj = obj;
    }
    
    public JSONObject getObj() {
        return obj;
    }}
    

    And put into the bundle:

    Parcel p = new Parcel(data);
        Bundle args = new Bundle();
        args.putSerializable("events", p);
    

    Finally, you can get the JSONObject back using:

    JSONObject obj = ((Parcel) ((Bundle) getArguments()).getSerializable("events")).getObj();
    

提交回复
热议问题