I have two activities. One is main activity and another is settings activity. In settings activity I am setting a color variable.
This I want to access in main activity as default color which is set in settings activity.
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.
How to save this variable in settings activity? I want to save color as a default for events in settings activity.
Thank you.
Edit :
I tried this using shared preferences but still i don't get default color in main activity.
In settings:
((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(); In main activity:
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE); mColor = sharedPref.getInt("color",0);