0

I have Activity #1: and I move to #Activity 2

Activity1:

Intent PostLogin = new Intent(getApplicationContext(), activity2.class);
        PostLogin.putExtra("email",emailOfUser);
        PostLogin.putExtra("token", authToken);
        PostLogin.putExtra("url", url);
        startActivity(PostLogin);

Activity #2:

ONCREATE ACTIVITY 2:


Intent loginActivity = getIntent();
        token = loginActivity.getStringExtra("token");
        email = loginActivity.getStringExtra("email");
        url = loginActivity.getStringExtra("url");


MOVING TO ACTIVITY 3

 Intent createOrJoin = new Intent(getApplicationContext(), activity3.class);
            createOrJoin.putExtra("token", token);
            createOrJoin.putExtra("url",url );
           // createOrJoin.putExtra("token", );
            startActivity(createOrJoin);

ACTIVITY 3 MOVING BACK TO ACTIVITY 2

Intent backtoPost = new Intent(getApplicationContext(), activity2.class);
                        startActivity(backtoPost);
                        finish();

So I initially have info in Activity 2 I got from Activity 1. Then from Activity 2 I go to Activity 3, where after some stuff I come back to Activity 2.

How can I still have the values of token, email, url?

user7361276
  • 229
  • 2
  • 4
  • 11

1 Answers1

0

There are multiple ways of doing this.

  1. One simple way is that you can have them in a variable.

    public class YourActivity extends Activity {
    
        String email;
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate();
            // Set content view etc
            email = getIntent().getStringExtra("email");
        }
    }
    
  2. Another better way is to save those variables that you need when onSaveInstancestate is called and then restore them in onCreate or onRestoreInstance. Check following questions for details: onSaveInstanceState () and onRestoreInstanceState () and When are onSaveInstanceState() and onRestoreInstanceState() called, exactly? for how to use them.

Community
  • 1
  • 1
Shobhit Puri
  • 25,769
  • 11
  • 95
  • 124