如何设置两个不同的WakefulIntentService AlarmListeners? [英] How to set two different WakefulIntentService AlarmListeners?

查看:135
本文介绍了如何设置两个不同的WakefulIntentService AlarmListeners?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Commonsware的WakefulIntentService( https://github.com/commonsguy/cwac-wakeful)来触发在我的Andr​​oid应用程序定期作业(更新图像的高速缓存)。到目前为止好,但我想添加不同的WakefulIntentService,做不同的工作,在不同的时间间隔。

我不知道如果我能做到这一点,怎么样。此刻,我安排一个报警是这样的:

  WakefulIntentService.scheduleAlarms(新CacheAlarmListener(),mContext,真正的);

CacheAlarmListener的实现是这样的:

  @覆盖
公共无效scheduleAlarms(AlarmManager alarmManager,的PendingIntent的PendingIntent,上下文的背景下){
    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime()+ 60000,AlarmManager.INTERVAL_HALF_HOUR,的PendingIntent);
}@覆盖
公共无效sendWakefulWork(上下文的背景下){
    WakefulIntentService.sendWakefulWork(背景下,CacheRefreshService.class);
}

通源$ C ​​$ C来看,<一个href=\"https://github.com/commonsguy/cwac-wakeful/blob/master/src/com/commonsware/cwac/wakeful/AlarmReceiver.java#L56\"相对=nofollow> getListener(上下文) AlarmReceiver 似乎找到并引发一个AlarmListener。我错了,或者是有另一种方式来安排报警或设置不同的PendingIntent?

基本上,我想可以注册一个新的,独立的 AlarmListener ,或者至少能够找出哪些 WakefulIntentService 送工作,在 sendWakefulWork(上下文)方法。


解决方案

  

到目前为止好,但我想添加不同的WakefulIntentService,做不同的工作。


您不必这样做。一个 WakefulIntentService 可以做多件事情,根据不同的意图特性(例如,操作字符串,演员)。拥有多个在同一项目 WakefulIntentService 的实施是未经检验的 - 除非有人能说服我它的必要性,是不受支持


  

从AlarmReceiver的getListener(上下文)方法似乎找到并引发一个AlarmListener。我错了。


没有,你是正确的。


  

有另一种方式来安排报警或设置不同的PendingIntent?


请按照对项目的README 中的基本使用的说明。


  

或者至少能够找出哪些WakefulIntentService的工作发送给


请只能有一个 WakefulIntentService


  

我需要能够触发两个不同的服务。


请只能有一个 WakefulIntentService

I'm using Commonsware's WakefulIntentService (https://github.com/commonsguy/cwac-wakeful) to trigger a periodic job in my Android application (updating a cache of images). So far so good, but I want to add a different WakefulIntentService, to do a different job, at a different time interval.

I'm not sure if I can do this and how. At the moment, I'm scheduling an alarm like this:

WakefulIntentService.scheduleAlarms(new CacheAlarmListener(), mContext, true);

The implementation of CacheAlarmListener is this:

@Override
public void scheduleAlarms(AlarmManager alarmManager, PendingIntent pendingIntent, Context context) {
    alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 60000, AlarmManager.INTERVAL_HALF_HOUR, pendingIntent);
}

@Override
public void sendWakefulWork(Context context) {
    WakefulIntentService.sendWakefulWork(context, CacheRefreshService.class);
}

Looking through the source code, the getListener(Context) method from AlarmReceiver seems to find and trigger a single AlarmListener. Am I wrong, or is there another way to schedule an alarm or setting a different PendingIntent?

Basically, I would like to be able to register a new, separate AlarmListener, or at least be able to figure out which WakefulIntentService to send the work to, in the sendWakefulWork(Context) method.

解决方案

So far so good, but I want to add a different WakefulIntentService, to do a different job

You do not need to do that. A single WakefulIntentService can do multiple things, based on different Intent characteristics (e.g., action strings, extras). Having multiple WakefulIntentService implementations in the same project is untested -- and unless somebody can convince me of its necessity, is unsupported.

the getListener(Context) method from AlarmReceiver seems to find and trigger a single AlarmListener. Am I wrong

No, you are correct.

is there another way to schedule an alarm or setting a different PendingIntent?

Follow the "Basic Usage" instructions on the project's README.

or at least be able to figure out which WakefulIntentService to send the work to

Please only have one WakefulIntentService.

I need to be able to trigger two different services.

Please only have one WakefulIntentService.

这篇关于如何设置两个不同的WakefulIntentService AlarmListeners?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆