How to access data from another activity?
<p>I have two activities. One is main activity and another is settings activity. In settings activity I am setting a color variable.</p>

<p>This I want to access in main activity as default color which is set in settings activity.</p>

<p>I tried to declare color as static variable and access it in another activity. But the problem is if I directly open main activity I don't get the color as it dose not get set in settings activity. </p>

<p>How to save this variable in settings activity? I want to save color as a default for events in settings activity.</p>

<p>Thank you.</p>

<p>Edit :</p>

<p>I tried this using shared preferences but still i don't get default color in main activity.</p>

<p>In settings:</p>

<pre><code> ((GradientDrawable)selectColor.getBackground()).setColor(Color.BLUE);
    mColor = Color.BLUE;

    SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putInt("color",mColor);
    editor.commit(); 
</code></pre>

<p>In main activity:</p>

<pre><code>    SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
    mColor = sharedPref.getInt("color",0);
</code></pre>