【问题标题】:How to keep the IntentService's attributes persistent?如何保持 IntentService 的属性持久化?
【发布时间】: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


    【解决方案1】:

    那么,最佳做法是什么?

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

    【讨论】:

      猜你喜欢
      • 2013-09-17
      • 1970-01-01
      • 2015-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-06
      • 2017-01-10
      • 2012-01-05
      相关资源
      最近更新 更多