About getSharedPreferences

58 Views Asked by At

I have a MainActivity with two EditTexts and a button "Save". I also have a second activity with two EditText and a button "Load".

When I put some data in EditText in MainActivity, I press the "Save" button and I get the second activity with the "Load" button. Then, when I press the "Load" button I get in the edittext of the second activity the saved data.

The problem is that I want to get that saved data in the edit text of the MainActivity so I can put some new data and save it. I am using the getSharedPreferences method.

1

There are 1 best solutions below

0
On

What you could do instead is something like this:

public class ActivityA {
    public void onButtonClicked() {
        Intent activityBIntent = new Intent(ActivityA.this, ActivityB.class);
        activityBIntent.putString("DATA", editText.getText().toString());
        startActivity(activityBIntent);
    }
}

You can then retrieve that text via:

String s = getIntent().getStringExtra("DATA");