Transfer values ​​from one screen to another?

I need to pass data (String) from one screen to another. When I click the button, I need to transfer the values ​​from the first screen to the next screen.

+1
source share
3 answers

You can transfer data as additional functions in the intent that triggers the second action:

Intent myIntent = new Intent(view.getContext(), NextActivity.class); myIntent.putExtra("extra", id); startActivityForResult(myIntent, 0); 

In the oncreate method of your profile activity, you can access additional functions:

 int id = getIntent().getStringExtra("extra"); 

If you're new to Android, this can help read examples in developer docs, like a notepad tutorial.

+9
source

Register onClickListener for the button and pass the necessary data by adding it to the Intent.

 Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Activity1.this, Activity2.class); intent.putExtra("extra", data); startActivity(intent); }); 

You can get the data in Activity2 on

 String extra = getIntent().getStringExtra("extra"); 
+3
source

The best way to do this (since you can access this value from anywhere), sharedPrefrences can be used. But it affected your application.

http://developer.android.com/reference/android/content/SharedPreferences.html

0
source

Source: https://habr.com/ru/post/898433/


All Articles