【发布时间】:2014-01-06 19:56:38
【问题描述】:
在这里,我编写了一个代码,通过使用意图将数据从一个活动传递到另一个活动。如果我需要在我的代码中进行任何更正,请告诉我。
OnClickListener buttonListener = new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent nextIntent = new Intent(getApplicationContext(), SecondActivity.class);
nextIntent.putExtra("firstname", "Siva");
nextIntent.putExtra("Secondname", "Kumar");
startActivity(nextIntent);
Toast.makeText(getApplicationContext(),"SignIn Button Clicked", Toast.LENGTH_SHORT).show();
}
};
第二个活动:
OnClickListener backListener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent backIntent = new Intent(getApplicationContext(), MainActivity.class);
Intent receivedIntent = getIntent();
Bundle bundleData = receivedIntent.getExtras();
bundleData.getString("firstname");
bundleData.getString("secondname");
startActivity(backIntent);
}
};
【问题讨论】:
-
在您的第二个活动中更正您的“第二名”。
-
有具体问题吗?
-
@laalto 我没有在模拟器中得到输出