I
I
IgorPlays2021-03-07 12:26:48
Java
IgorPlays, 2021-03-07 12:26:48

How to pass data to another activity in android app?

I need to pass text from EditText to another activity.
I have 2 classes TransitionActivity and CompleteActivity, in 1 I can pass a variable, in the second it does not. Tried a lot of things, but didn't work. What to do?

Transition Activity >

public class TransitionActivity extends AppCompatActivity {

    String moneys;
    EditText money;
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_transition);

        EditText money = (EditText)findViewById(R.id.money);

 money.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                moneys = money.getText().toString();
                complete.setText(moneys);

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });


XML code
<EditText
            android:inputType="number"
            android:textCursorDrawable="@drawable/color_cursor"
            android:id="@+id/money"
            android:background="@color/white"
            android:text="1000"
            android:textSize="82px"
            android:layout_gravity="center"
            android:textAlignment="center"
            android:layout_height="match_parent"
            android:layout_width="600px"
            tools:ignore="RtlCompat" />

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2021-03-07
@IgorPlays

In a modern android application, there should be one activity. More is possible, but usually not necessary, and you need to clearly understand why. Screens are broken down into fragments.
Data in an activity can be passed inside an Intent.

J
Jacen11, 2021-03-08
@Jacen11

Intent (main)
Static field for activity (cannot be)
SharedPreferences
database
Using internal storage
Using external storage
ViewModel
Bus

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question