2

我必须进行活动AnswerQuestion.javaSendAnswerToServer.java并且我想将数据从第一个活动发送到另一个活动

在 AnswerQuestion 活动中,我这样写:

Bundle basket = new Bundle();
basket.putString("time", timeToAnswer+"");
Intent goToSendServer = new Intent(AnswerQuestion.this, SendAnswerToServer.class);
goToSendServer.putExtras(basket);
startActivity(goToSendServer);

我的问题是我要在 SendAnswerToServer 活动上写什么,谢谢

4

1 回答 1

11

在 SendAnswerToServer 活动中:

 @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
     }
于 2012-06-24T18:10:54.467 回答