Pass value from one Android activity to another

Since two activities have no shared space (by default), it is not possible to grab that value/variable from the original activity. One has to not only find a way to store this value in the original activity, but find a way to access it from the newly created activity. This allows data sharing between activities to some extent. The value has to accessible at activity initialization as well as at any other point in activity life-cycle.
1 answer

Use putExtra(...) function to pass values between Android activities

Intent class function putExtra(String name, char[] value) is able to add extended data to the intent. The first parameter (name) must include a package prefix. For example if we wanted to create a new email activity and pass the value some email address we would do the following (assume we call from activity class):
Intent email = new Intent(getActivity(), EmailActivity.class);
email.putExtra(MainActivity.CURRENT_EMAIL, "someemail@domain.com");

where as MainActivity.CURRENT_EMAIL acts as a key in this case. Its value must contain package name, for example: "com.example.EMAIL". Further reading in documentation under section Extras: https://developer.android.com/guide/components/intents-filters.html

Taggings: