0

I have two class files. One which creates and stores a value in a string (PINString). The second class file uses the variable to show in a textView. as shown below: Currently the calue of the variable PINString isnt being passed through

First

  {


        //
        int randomPIN = (int)(Math.random()*9000)+1000;

        //
        String PINString = String.valueOf(randomPIN);

         Intent i = new Intent(getBaseContext(),verification.class);
     i.putExtra("PINString", PINString);//transfer string
     startActivity(i);

    }

Second

           public void onClick(View view) 

           {

            String PINString;

            Bundle bundle = getIntent().getExtras();
            PINString = bundle.getString("SMSDemo.PINString");



               TextView textView2 = (TextView) findViewById(R.id.textView2);

               textView2.setText(PINString);

2 Answers 2

2

You pass your variable as "PinString":

i.putExtra("PINString", PINString);//transfer string

So, instead of this:

PINString = bundle.getString("SMSDemo.PINString");

Use

PINString = bundle.getString("PINString");
Sign up to request clarification or add additional context in comments.

Comments

1

You have

 i.putExtra("PINString", PINString);
 // key is PINString

The keys must match. Use PINString while you get the string also

PINString = bundle.getString("PINString");

Also follow java naming conventions while naming vairables

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.