Android send data from activity to activity using bundle

user1476841 picture user1476841 · Jun 24, 2012 · Viewed 8.7k times · Source

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

Answer

ρяσѕρєя K picture ρяσѕρєя K · Jun 24, 2012

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
     }