问题
i have to activities AnswerQuestion.java
and SendAnswerToServer.java
, and i want to send data from first activity to another one
on the AnswerQuestion activity i write this:
Bundle basket = new Bundle();
basket.putString("time", timeToAnswer+"");
Intent goToSendServer = new Intent(AnswerQuestion.this, SendAnswerToServer.class);
goToSendServer.putExtras(basket);
startActivity(goToSendServer);
my question what have i to write on the SendAnswerToServer activity , thank you
回答1:
in SendAnswerToServer Activity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getIntent().getExtras();
if(bundle !=null)
{
//ObtainBundleData in the object
String strdata = bundle.getString("time");
//Do something here if data received
}
else
{
//Do something here if data not received
}
来源:https://stackoverflow.com/questions/11179936/android-send-data-from-activity-to-activity-using-bundle