Red-Folder / Cordova-Plugin-BackgroundService

BackroundService plugin for use with Cordova (PhoneGap)
144 stars 85 forks source link

Service member variables reset on app close #15

Closed 1derwood closed 11 years ago

1derwood commented 11 years ago

I'm passing a value to the background service from JS via setConfiguration and storing that value in a member variable for use in each call to doWork. This all works swimmingly as long as my app is alive. However, if I suspend the app and open a couple of other apps, I notice that initialiseLatestResult is called and my member variable has lost its value. The service continues to run at the requested interval but it seems to have been reset. Any way around this?

teusink commented 11 years ago

In your Java code, make use of SharedPreferences. In SetConfig you will write the value to your SharedPref. In doWork you will read it.

Works for me.

See my blog for some code examples for SharedPreferences: http://teusink.blogspot.nl/2013/09/phonegap-android-androidpreferences.html?m=1

1derwood commented 11 years ago

Works great, thanks!