Passing data between two Screen Android[Tutorial]

Hi, today i'm going to discuss about on how we can pass parameter between two activities. before starting you need some basic knowledge on how android works and first android example .
STEP 1 :
Create New Project From Eclipse. Open main activity and write the code to get all the data from test box or any input by gettext(); method like
EditText NameRes = (EditText) findViewById(R.id.name);
String Name=NameRes.getText().toString());
STEP 2:
Now make new intent that open another activity in our case second screen.
Intent i = new Intent(getApplicationContext(), Second.class);
STEP 3:
Now put extra string that you have to pass from screen one that is in our case string name.
//i.putExtra("NEW_VARIABLE_NAME","VALUE");

i.putExtra("id","Name");
STEP 4:
Now start the activity.
StartActivity(i);
STEP 5:
Create Second.java file and catch the content from screen one by writing the code
Bundle extras = getIntent().getExtras();
if (extras != null) { String value = extras.getString("new_variable_name");
STEP 6:
Don't miss some basic configuration liike. - defining resourse in xml file. -put both the acitivity define in manifest file. that's sit. you are done. IF YOU HAVE DOUBT OR ANY QUERY LET ME KNOW.........FEEL FREE TO ASK IN COMMENT.

0 comments:

Post a Comment

 
TheMobiForest - Ultimate Forest Of Technology © 2012-2014 | Designed by Cheap TVS, in collaboration with Vegan Breakfast, Royalty Free Images and Live Cricket Score