-1

I am new to Android, so the name of the question might not be correct. Basically, I get a price as a JSONObject response (this is happening in fragment).

   public void onResponse(JSONObject response) {
        try {
            int price = response.getInt("price");

        } catch (JSONException ex) {

        }
    }

Now, how can I pass the value of the price to another activity and set it as setText in a TextView in that particular activity?

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
jlively
  • 735
  • 2
  • 9
  • 29

1 Answers1

1

Use this way.

From Current Activity

  public void onResponse(JSONObject response) {
        try {
            int price = response.getInt("price");
            Intent mIntent = new Intent(CurrentActivity.this, TargetActivity.class);
            mIntent.putExtra("price", price);
            startActivity(mIntent);
        } catch (Exception ex) {

        }
    }

From Target Activity's onCreate

   TextView txtPrice = (TextView)findViewById(R.id.txtPrice);
   txtPrice.setText(getIntent().getIntExtra("price"));
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95