Thursday, June 18, 2015

Passing Data Between Activities in Android

passing data from one activity to another activity in android using intent.

Suppose two Activity : FirstActivity and SecondActivity. if we want to send data from FirstActivity  to SecondActivity  then we move from another activity using Intent 

We Send data in key-value form.

 String name=InvokeCode;

this name send to another activity then,

                       Intent i=new Intent(FirstActivity .this,SecondActivity.class);
i.putExtra("value",name );
startActivity(i);

here value is key, and name is value. get data by key name 


Get Data From Intent:

get data from FirstActivity and get data by key and here key is "value" 

      
                        Intent i=getIntent();

                        if (i !=null) {
                           String data=i.getStringExtra("value");
                           }

and data is InvokeCode that was send from FirstActivity.

NOTE: if any issue to implement this code then comment..

No comments :

Post a Comment