This question has already been answered:
There is a service, there are activations, everyone has SharedPreferences :
Activity:
public class MainActivity extends AppCompatActivity { SharedPreferences sPref; SharedPreferences.Editor sPrefEdit; final String SAVED_TEXT = "saved_text"; ... @Override protected void onCreate(Bundle savedInstanceState) { sPref = getSharedPreferences(SAVED_TEXT,MODE_PRIVATE); sPrefEdit = sPref.edit(); ... and service:
public class HealthService extends Service { SharedPreferences sPref; SharedPreferences.Editor sPrefEdit; final String SAVED_TEXT = "saved_text"; ... @Override public void onCreate() { sPref = getSharedPreferences(SAVED_TEXT,MODE_PRIVATE); sPrefEdit = sPref.edit(); They have the same file preferences, but if the service writes something to the preferences, it sees the activation changes only after the application is restarted, and the service also sees the changes in preferences made by the activations only after the restart.
How to deal with it?