How to pass JSON Object to new activity

前端 未结 3 750
太阳男子
太阳男子 2020-12-10 17:58

I have an application that needs to download JSON from URL using AsyncTask and on onPostExecute() pass that JSON Object to next Activity using putExtra method, but I\'m cons

3条回答
  •  醉酒成梦
    2020-12-10 18:20

    In the Activity in which You are getting the JSON data write the following code to send to the TAB activity

    Intent i = new Intent(getApplicationContext(), Another_Activity.class);
                                i.putExtra("key", jsonObject.toString());
                                startActivity(i);
    

    to access the data ie JSON object Write the following code in tab Activity

       JSONObject jsonObject = new JSONObject(getIntent().getStringExtra("key"));
                        Toast.makeText(Another_Activity.this, ""+jsonObject.get("Your JSON VALUE"), Toast.LENGTH_SHORT).show();
    

    Your JSON VALUE is the filed which is present in the data. eg "Business Id" 1 here business id is the JSON value ,replace it with yours

提交回复
热议问题