Android的使用束从活动将数据发送到活动(Android send data from acti

2019-09-18 10:49发布

我必须活动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活动写,谢谢

Answer 1:

在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
     }


文章来源: Android send data from activity to activity using bundle