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的屬性嗎?什麼是最好的做法?