When I get the String value with int, I pay you...Only the viewers are coming in.

Asked 2 years ago, Updated 2 years ago, 94 views

//Second.class

f =fstE.getText().toString();       l = lstE.getText().toString();

Intent i = new Intent(Second.this, T1_text.class);
i.putExtra("lastName",l);
i.putExtra("firstName",f);
startActivity();

//T1_text.class

Intent i2 = getIntent();

F = i1.getStringExtra("firstName");
L = i1.getStringExtra("lastName");yo

I wrote it like this. It is treated as a null value when loaded as an int, and putExtra(fstE.getText().toString();) in Second If you import it like this, it will run properly.

What I want is to put it in an object and use it for various activities, but it doesn't fit in an object (Crying) They told me to set the global variable.

Application.class

public String l; String f;

public String getL(){
    return l;
}
public void setL(String l){
    this.l =l;
}

We did this, but it' Help me ㅠ<

intent string

2022-09-21 11:55

1 Answers


public class Name {
    private static Name INSTANCE;

    private String mFirstName;
    private String mLastName;

    public static Name get() {
        if (INSTANCE== null) {
            synchronized (Name.class) {
                if (INSTANCE== null) {
                    INSTANCE = new Name();
                }
            }
        }
        return INSTANCE;
    }

    public void setFirstName(String firstName) {
        mFirstName = firstName;
    }

    public String getFirstName() {
        return mFirstName;
    }

    /* Please also create a LastName.*/
}

As I wrote in the comments, check that the variable name I received with getIntent and the variable name using getStringExtra are different.

And the second...

What I want is to put it in an object and use it for various activities, but it doesn't fit in an object (Crying) Set the global variable

I think it's the use of a single tone pattern when you ask me to set the global variable. Create a Java file like above


// Save Where You Want
Name.get().setFirstName(fstE.getText().toString());

// Use Where You Want
String firstName = Name.get().getFirstName();

I hope you try it like this.


2022-09-21 11:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.