Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If it is just two activities then you can use Bundle to pass values. For more than two activities it is recommended you use SharedPreferences.</p> <p>Here is an example of using Bundle to pass values:</p> <pre><code> String sample="Hello World!"; Bundle b=new Bundle(); b.putString("key_sample",sample); Intent intent_sample=new Intent(this,Activity_Sample.class); intent_sample.putExtras(b); startActivity(intent_sample); </code></pre> <p>To get the passed values:</p> <pre><code> try{ Bundle get_bundle=getIntent().getExtras(); String get_string=get_bundle.getString("key_sample"); }catch(Exception e){ e.printStackTrace(); } </code></pre> <p>Check this out: <a href="http://www.codestacks.in/2013/03/bundle-values-activities/" rel="nofollow">http://www.codestacks.in/2013/03/bundle-values-activities/</a></p> <p>SharedPreferences Example:</p> <pre><code> public class SharedPreferencesDemo extends Activity { SharedPreferences shared_preferences; SharedPreferences.Editor shared_preferences_editor; String test_string = ""; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); shared_preferences = getSharedPreferences("shared_preferences_test", MODE_PRIVATE); test_string = shared_preferences.getString("test_key", "Default"); Toast.makeText(getApplicationContext(), test_string, Toast.LENGTH_SHORT) .show(); shared_preferences_editor = shared_preferences.edit(); shared_preferences_editor.putString("test_key", "Hello World"); shared_preferences_editor.commit(); test_string=shared_preferences.getString("test_key", "Default"); Toast.makeText(getApplicationContext(), test_string, Toast.LENGTH_SHORT).show(); } } </code></pre> <p>Here is the complete explanation: <a href="http://www.codestacks.in/sharedpreferences/" rel="nofollow">http://www.codestacks.in/sharedpreferences/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload