Question

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.

Was it helpful?

Solution

 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 );

OTHER TIPS

Use simple static variable. Or sharedpreferences for this purpose.

if(isUserValidated && isPasswordValidated)
{
  String s= getIntent().getStringExtra(total);// problem is here
  ....// In second activity
}

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

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");

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());

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 );
}

For this better solution is using shared preference in android. Store your value in shared preference and in 3rd activity get that value and used it as per your requirement.

For more detail :Example of Shared Preference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top