如果你打电话Activity1
——>Activity2
您可以UserName
通过此方法发送
Intent intent = new Intent(getBaseContext(), Activity2.class);
intent.putExtra("UserName ", UserName );
startActivity(intent);
要检索Extra()
in Activity2
,您需要此代码
String UserName = (String) getIntent().getSerializableExtra("UserName ");
希望这可以帮助
下面编辑以便更好地理解
public class Activity2 extends Activity {
private String UserName;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.activity_2);
UserName= (String) getIntent().getSerializableExtra("UserName");
Log.i(Tag, "UserName: "+ UserName);
}
// you can call this method from click or where ever you want
private void AnyMethod()
{
Intent intent = new Intent(getBaseContext(), Activity3.class);
intent.putExtra("UserName ", UserName );
startActivity(intent);
}
}