【发布时间】:2012-12-08 23:27:16
【问题描述】:
我已经开发了一个安卓应用程序。 在这里,我必须将值从第一个活动传递到第三个活动。
成功开发了从第一个活动传递到第二个活动的值。但是我无法将第二个活动的值传递到第三个活动。请帮助我如何开发这些。请帮助我。
这是我的第一个活动:
Intent i = new Intent(getApplicationContext(), CustomerLogin.class);
i.putExtra("GrandTotal", mGrandTotal);
startActivity(i);
第二个活动:
Intent in = getIntent();
Bundle b = getIntent().getExtras();
String total = b.getString("GrandTotal");
TextView grandtotal = (TextView) findViewById(R.id.grand_total);
grandtotal.setText("Welcome ," + total );
这里的值是从第一个活动成功传递到第二个活动。 现在我必须将这些值传递给第三个活动。我该怎么做。
现在这是我的第二个活动:
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);
}
这是我的第三个活动:
Bundle b = getIntent().getExtras();
String total = b.getString("GrandTotal");
TextView grandtotal = (TextView) findViewById(R.id.check);
grandtotal.setText("Welcome ," + total );
现在我必须运行应用程序,这意味着我正在获得第二个活动的总值。但我没有得到第三个活动的总值。请帮助我。这里做错了什么。
【问题讨论】:
-
尝试在第二个活动的 putextra 之前记录你的 s 变量,我认为你的 s 变量为空
-
使用 Singleton 类进行分享。 stackoverflow.com/a/7886046/1012284
标签: java android android-intent bundle pass-data