0
我建立一个应用程序,一IntentService定期运行使用AlarmManager:如何保持IntentService的属性持久?
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent serviceIntent=new Intent(NewsListActivity.this, LatestNewsRetrService.class);
PendingIntent pendingService=PendingIntent.getService(getApplicationContext(), 0, serviceIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), REFRESH_INTERVAL, pendingService);
大家都知道LatestNewsRetrService类被创建和销毁每次服务已运行;嗯,我的问题是,我想保留2个对象用在这个服务中,像属性,但这是不可能的,因为每次它们被重新创建。 我甚至试图把这些对象作为额外的服务意图,但他们不会更新。 那么,最佳做法是什么?我应该将这些对象保存为主Activity的属性吗?什么是最好的做法?