-5

I have an integer value in one activity, when I debug I can see there is a value be placed in. The value comes from a counter inside another function within the same class. I am trying to send the variable to another activity and display it in a TextView.

Sending Class:

 Intent intent = new Intent(TrackingActivity.this, StatActivity.class);
            intent.putExtra("yzValue" , getyzVal());
            startActivity(intent);

Receiving Class:

    Intent intent = getIntent();
    baValue = (TextView) findViewById(R.id.baValue);
    String baVal = intent.getStringExtra("yzValue") ;
    maxX.setText(String.valueOf(baVal));

I have tried various solution but it just displays NULL in the TextView.

Taslim Oseni
  • 4,610
  • 10
  • 34
  • 50
JamesD
  • 88
  • 6

1 Answers1

-2

Try this,

   String baVal = intent.getExtras().get("yzValue").toString() ;
MSD
  • 71
  • 8
  • What's wrong with this answer – MSD Feb 20 '18 at 13:41
  • This works thanks a mill. I don't know why it done a negative vote. – JamesD Feb 20 '18 at 13:42
  • Then accept my answer. – MSD Feb 20 '18 at 13:42
  • I have to wait 4 minutes it say, I will accept when it lets me. – JamesD Feb 20 '18 at 13:45
  • Correct! Your answer no longer has a negative vote.. ;-) Better 0 than <0. – Taslim Oseni Feb 20 '18 at 17:07
  • very bad way - oString() Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. You should check assignability then cast ... – ceph3us Feb 20 '18 at 17:57