如何保持意图服务的属性持久化?



我正在构建一个应用程序,其中IntentService使用AlarmManager:定期运行

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类是在每次运行服务时创建并销毁的;好吧,我的问题是,我想保留在这个类似服务的属性中使用的两个对象,但这是不可能的,因为每次都会重新创建它们。我甚至试图将这些对象作为额外对象放入服务意图中,但它们不会更新。那么,最佳做法是什么?我应该将这些对象保存为主"活动"的属性吗?做什么最好?

那么,最佳做法是什么?

将它们存储在文件中。

最新更新