How should I communicate between activities? [duplicate]

Use Bundle please read sth more about it. http://developer.android.com/reference/android/os/Bundle.html

1) Use the Bundle from the Intent:

Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);

2) Create a new Bundle

Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.extras.putString(key, value);
mIntent.putExtras(mBundle);

3) Use the putExtra() shortcut method of the Intent

Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value);

Then, in the launched Activity, you would read them via:

String value = getIntent().getExtras().getString(key);

This is the proper way to do that. Another way is SharedPreferences. http://developer.android.com/training/basics/data-storage/shared-preferences.html

Leave a Comment