Skip to content

Instantly share code, notes, and snippets.

@AkaashSaini
Created July 7, 2021 11:22
Show Gist options
  • Save AkaashSaini/b17d42621d013f4aba32792d53a46b98 to your computer and use it in GitHub Desktop.
Save AkaashSaini/b17d42621d013f4aba32792d53a46b98 to your computer and use it in GitHub Desktop.
Passing Data from one activity to other
Use following code in first activity
Intent intent=new Intent(Main.this,second.class);
Intent.putExtra(“val”, t1.getText().toString()); //parameter, value
startActivity(intent)
putExtra() – It is used to store parameter with value in intent.
Write following code in second activity
TextView tv=(TextView) findViewById(R.layout.tv1);
Tv.setText(getIntent().getExtras().getString(“val”));
getIntent() – It is used to find recent applied intent. It is member function of Activity class.
getExtras() – It is member of Intent class and used to grab parameters from intent.
getString() – It is used to fetch value of parameter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment