Reputation: 623
I have an App which doing stuff in a Service in background (also when Screen is swiched off). I start the service in an Activity which following code.
Intent i=new Intent(this, AppService.class);
i.putExtra(AppService.VOL_ALM, amanager.getStreamVolume(amanager.getStreamVolume(AudioManager.STREAM_ALARM)));
PendingIntent pi = PendingIntent.getService(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pi);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 *60, pi);
The code in trhe Service looks like this:
public int onStartCommand(Intent intent, int flags, int startId) {
test = intent.getIntExtra(VOL_ALM, 0);
timer = new Timer("TweetCollectorTimer");
timer.schedule(updateTask, 0, 15 * 1000L);
return(START_NOT_STICKY);
}
In the Service I have to change the variable "test" and work with it. But I always lose the changed value of the variable because onStartCommand sometimes executed. I tried to store the variable with preferences, but I also need the original value of the variable when I start the service. The best way would be changing the data "VOL_ALM" from the intend in a Method. But is that possible?
Thanks in advance
Upvotes: 0
Views: 295
Reputation: 8641
?
Store both values in SharedPreferences? That's the accepted method for persisting values.
Upvotes: 1