Skip to content

Instantly share code, notes, and snippets.

@gWOLF3
Forked from uknowmeright/Android Pass Variable
Created December 5, 2018 06:08
Show Gist options
  • Save gWOLF3/665655dcf6c788fa3c6687c7c1da73c3 to your computer and use it in GitHub Desktop.
Save gWOLF3/665655dcf6c788fa3c6687c7c1da73c3 to your computer and use it in GitHub Desktop.
How to pass variables to a new activity in Android (Android Studio)
//step 1:
import android.content.Intent;
//step 2: add to activity you want to sav variables from
Intent i = new Intent(getApplicationContext(), ActivityName.class);
i.putExtra("someVariable","variableValue");
startActivity(i);
//step 3: add to activity you want to pulll variables from
Bundle extras = getIntent().getExtras();
if (extras != null) {
String someVariable = extras.getString("someVariable");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment