Android使用bundle将活动数据发送到活动

时间:2012-06-24 18:06:47

标签: android android-intent android-event

我必须参加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活动上写了什么,谢谢

1 个答案:

答案 0 :(得分: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
     }