Android send data from activity to activity using bundle

霸气de小男生 提交于 2019-12-11 03:31:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!