0

我正在构建一个应用程序,其中使用 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 的属性吗?最好的办法是什么?

4

1 回答 1

0

那么,最佳实践是什么?

将它们存储在一个文件中。

于 2012-01-25T13:11:57.747 回答