Android: change variables (counters) of a closed application using a service -


stackoverflow community.

I have a problem which I am trying to solve a few days later.

I am running a service in an Android application that receives and sends messages and for those messages, I have counters who save the sent SMS and the error of errors. For example, when a message is sent, the counter adds 1 and displays the total on the screen (not in the focusable editable view).

There is one thing that ties my service, so I can turn it on or off as per my needs. The app is running when everything works fine, but if it's lost my variable has lost, but I need to count some of the messages and show the value when the user open the app again. How can i do this

I am using the Shared Preferences variable to save these numbers and other configurations, but when the app is killed, these numbers can not continue to grow.

When the application stops, can I save the counter values ​​somewhere? Can I stop the application for closed preferences from the service? What if I use a content provider? Can I access it from the service run even after the app is closed?

Regards.

There is no problem reaching service-sharing priorities, therefore, simply saving your variable on your services Reload () method and creature;

It should work to achieve the preference:

  reference ctx = getApplicationContext); Shared references prefs = PreferenceManager.getDefaultSharedPreferences (ctx);   

This is a great answer:

Comments