【发布时间】:2012-02-18 13:18:09
【问题描述】:
我正在构建一个应用程序,其中使用 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 的属性吗?最好的办法是什么?
【问题讨论】:
标签: android android-alarms intentservice