0

I have develop one android application. Here i have to pass the value from 1st activity to third activity.

The value is passed from 1st to 2nd activity successfully developed.But i can't pass the value from 2nd to third activity.please help me how can i develop these.please help me.

This is my 1st activity:

     Intent i = new Intent(getApplicationContext(), CustomerLogin.class);
                i.putExtra("GrandTotal", mGrandTotal);
                startActivity(i);

The 2nd activity:

Intent in = getIntent();
Bundle b = getIntent().getExtras();
String total = b.getString("GrandTotal");
TextView grandtotal = (TextView) findViewById(R.id.grand_total);
 grandtotal.setText("Welcome ," + total );

Here the value is pass from 1st to 2nd activity successfully. Now i have to pass these value to third activity.how can i do.

Now this is my 2nd activity:

if(isUserValidated && isPasswordValidated)
{
    String s= getIntent().getStringExtra(total);
    Intent intent = new Intent(CustomerLogin.this,PayPalIntegrationActivity.class);
    intent.putExtra("GrandTotal", s);
    intent.putExtra("login",username.getText().toString());
    startActivity(intent);

}

This is my third activity:

    Bundle b = getIntent().getExtras();

    String total = b.getString("GrandTotal");
    TextView grandtotal = (TextView) findViewById(R.id.check);
    grandtotal.setText("Welcome ," + total );

Now i have to run the app means am getting the total value on 2nd activity.but am not getting the total value in 3rd activity.please help me.whats am doing wrong here.

user1897014
  • 143
  • 4
  • 14

6 Answers6

0

Use simple static variable. Or sharedpreferences for this purpose.

kumar
  • 691
  • 1
  • 7
  • 16
0
if(isUserValidated && isPasswordValidated)
{
  String s= getIntent().getStringExtra(total);// problem is here
  ....// In second activity
}

change to String s= getIntent().getStringExtra("GrandTotal");

Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
  • am getting null value only from 2nd to 3rd activity.this is my 2nd activity code:pastie.org/5561078.please check my code and give me solution for these. – user1897014 Dec 21 '12 at 11:48
0
 Intent i = new Intent(getApplicationContext(), CustomerLogin.class);
 i.putExtra("GrandTotal", mGrandTotal);
 startActivity(i);

The 2nd activity:

Bundle b = getIntent().getExtras();
String total = b.getString("GrandTotal");
TextView grandtotal = (TextView) findViewById(R.id.grand_total);
grandtotal.setText("Welcome ," + total );   

  if(isUserValidated && isPasswordValidated)  {      
      Intent intent = new Intent(CustomerLogin.this,PayPalIntegrationActivity.class);
      intent.putExtra("GrandTotal", total);
      intent.putExtra("login",username.getText().toString());
      startActivity(intent);    
    }

This is my third activity:

Bundle b = getIntent().getExtras();    
String total = b.getString("GrandTotal");
String name = b.getString("login");
TextView grandtotal = (TextView) findViewById(R.id.check);
grandtotal.setText("Welcome ," + total );
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
User
  • 1,251
  • 1
  • 14
  • 19
  • the null value only displayed here from 2nd to third.this is my 2nd activity code:http://pastie.org/5561078 – user1897014 Dec 21 '12 at 11:44
  • check ur code once "if" condition is executing or else is executing – User Dec 21 '12 at 11:48
  • if condition only executed in my code.getting null on 3rda ctivity – user1897014 Dec 21 '12 at 12:41
  • This is my 1st activity code:http://pastie.org/5564017 This is my 2nd activity code:http://pastie.org/5564018 This is my 3rd activity code:http://pastie.org/5564020 please check my code and give me solution.i have changed my code.code is correct only.but am getting null value.please check it. – user1897014 Dec 22 '12 at 04:19
  • i have to created the String total on public. total = b.getString("GrandTotal"); now i got the o/p.thanks for your help – user1897014 Dec 24 '12 at 06:10
0

Replace

 if(isUserValidated && isPasswordValidated)
    {
        String s= getIntent().getStringExtra(total); // Replace this line
        Intent intent = new Intent(CustomerLogin.this,PayPalIntegrationActivity.class);
        intent.putExtra("GrandTotal", s);
        intent.putExtra("login",username.getText().toString());
        startActivity(intent);

    }

with

String s= getIntent().getStringExtra("GrandTotal");
Renjith
  • 5,783
  • 9
  • 31
  • 42
  • am getting null value only from 2nd to 3rd activity.this is my 2nd activity code:pastie.org/5561078.please check my code and give me solution for these. – user1897014 Dec 21 '12 at 11:49
0

If you need to pass the exact same values, you can just use:

Intent intent = new Intent(CustomerLogin.this,PayPalIntegrationActivity.class);
intent.putextras(this.getIntent.getExtras());
alistair
  • 1,164
  • 10
  • 27
  • This is simple. It is intended to be put in Activity 2. It puts the extras given from Activity 1 into the intent for Activity 3. It assumes you don't want to change the extras. – alistair Dec 22 '12 at 14:34
0

try this in your thired activity

Edit :

if(getIntent().getStringExtra("GrandTotal")!= null)
{
      String total =getIntent().getStringExtra("GrandTotal"); <---------------
      TextView grandtotal = (TextView) findViewById(R.id.check);
      grandtotal.setText("Welcome ," + total );
}
MAC
  • 15,799
  • 8
  • 54
  • 95
  • am getting null value only from 2nd to 3rd activity.this is my 2nd activity code:pastie.org/5561078.please check my code and give me solution for these. – user1897014 Dec 21 '12 at 11:48