-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,672
  • 11
  • 72
  • 123
jlively
  • 715
  • 1
  • 9
  • 27

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
  • 19,001
  • 8
  • 65
  • 90