Passing JSONObject into another activity

后端 未结 7 1956
情歌与酒
情歌与酒 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 05:12

    From Current Activity

    Intent mIntent = new Intent(CurrentActivity.this, TargetActivity.class);
    mIntent.putExtra("ITEM_EXTRA", json_object.toString());
    startActivity(mIntent);
    

    From Target Activity's onCreate

    try {
       json_object = new JSONObject(getIntent().getStringExtra("ITEM_EXTRA"));
    
       Log.e(TAG, "Example Item: " + json_object.getString("KEY"));
    
    } catch (JSONException e) {
       e.printStackTrace();
    }
    

提交回复
热议问题