How to pass a String variable from a popup to the class who called it?

0

I need to know how to pass a variable String from a popup (it's an activity class) that was called from another activity, the idea when I click on a button to accept it in the popup returns me to the activity class without restarting it, if not returning to was before opening the popup but with an additional variable String. I have searched several ways, but I can not find it in the way that the activity does not restart, please help me.

    
asked by Koke143 23.07.2018 в 01:13
source

1 answer

-1

By not seeing the code, I can only suggest you use onSaveInstanceState ()

Basically what it does is to rebuild your activity after having finished it for the life cycle that your app uses, either for a finish or for simply closing the app. The activity is reconstructed with pre-stored values in the object Bundle , which will serve to recover the data that will inflate that Activity again.

  

To save additional information about the status of the activity,   you must replace the callback method   onSaveInstanceState (). The system calls this method when the   user is abandoning your activity and passes the Bundle object that   will be saved in case your activity is destroyed in a   unexpected If more later the system must recreate the   instance of the activity, this passes the same object Bundle to the   methods onRestoreInstanceState () and onCreate ().

Hint of code provided by the documentation

To save additional status information for your activity, you must implement onSaveInstanceState() and add key-value pairs to the Bundle object. For example:

static final String STATE_SCORE = "playerScore";
static final String STATE_LEVEL = "playerLevel";
...

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    // Save the user's current game state
    savedInstanceState.putInt(STATE_SCORE, mCurrentScore);
    savedInstanceState.putInt(STATE_LEVEL, mCurrentLevel);

    // Always call the superclass so it can save the view hierarchy state
    super.onSaveInstanceState(savedInstanceState);
}

Here's how you can restore certain status information in onCreate()

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); // Always call the superclass first

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        // Restore value of members from saved state
        mCurrentScore = savedInstanceState.getInt(STATE_SCORE);
        mCurrentLevel = savedInstanceState.getInt(STATE_LEVEL);
    } else {
        // Probably initialize members with default values for a new instance
    }
    ...
}

To pass a new String variable to the activity that you want to see again, just use putExtra ()

I hope it serves you.

    
answered by 23.07.2018 в 04:10