0

I wanted to get the name of pizza on bill page put it isn't displaying(blank).

Menu.java:

bundle = new Bundle();
        bundle.putString("name",pizzaName);
y = new Intent(this,Bill.class);
        y.putExtras(bundle);
startActivity(y);

Bill.java:

text1=(TextView)findViewById(R.id.textView6);
y= new Intent();
        bundle=getIntent().getExtras();
        Name=bundle.getString("name");
text1.setText();

Output:

Shubham
  • 9
  • 2

4 Answers4

0

You do not need to do y= new Intent(); in Bill.java

Change code in Bill.java as follows. Also, for better naming convention, change Bill.java to BillActivity.java

    TextView text1 = (TextView) findViewById(R.id.textView6);
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        String name = bundle.getString("name");
        text1.setText(name);
    }
Gani
  • 3
  • 2
0

You can simply pass and retrieve value like this.

// Creating and initializing an Intent object
Intent intent = new Intent(this, NextActivity.class);

// Attach the key value pair using putExtra to this intent
String pizza = "Margherita";
intent.putExtra("PIZZA_NAME", pizza);

// Start the activity
startActivity(intent);
// Get the current intent
Intent intent = getIntent();

// Get the attached extras from the intent
// We should use the same key as we used to attach the data.
String pizza = intent.getStringExtra("PIZZA_NAME");

Sumit Saurabh
  • 1,366
  • 1
  • 19
  • 33
-1

Remove y= new Intent(); in your bill.class

Manu
  • 53
  • 1
  • 2
  • 12
-1

No need to get y= new Intent(); when you get data from bundle

text1=(TextView)findViewById(R.id.textView6);

bundle=getIntent().getExtras();

Name=bundle.getString("name");

text1.setText();

archana
  • 1
  • 1
  • 1