- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要在我的应用程序运行时和启动时处理通过 AlarmManager 发布的 Intent 。我已经编写了 JobIntentService 的子类来处理 Intent ,但它没有按预期工作:没有调用 onHandleWork。
我的实现在处理程序是一个 IntentService 时有效,除了在启动时由于后台服务的限制。因此,我尝试改用 JobIntentService。
public class MyJobIntentService extends JobIntentService
{
public int onStartCommand(@Nullable Intent intent, int flags, int startId)
{
// This gets called with the intent given to AlarmManager
return super.onStartCommand(intent, flags, startId);
}
public static void enqueueWork(Context context, Intent work)
{
// Not called
enqueueWork(context, NotificationService.class, JOB_ID, work);
}
public void onHandleWork(@NonNull Intent intent)
{
// Not called
...
}
// No other methods overridden
}
onStartCommand 被调用。文档说这个方法:
Processes start commands when running as a pre-O service, enqueueing them to be later dispatched in onHandleWork(Intent).
我不知道这里的“稍后”是什么意思,但实际上并没有调用 onHandleWork,尽管已经以预期的目的调用了 onStartCommand。
我已阅读类似问题的答案并确保我不会覆盖其他方法。我还为服务创建了一个 list 条目,我认为它是正确的 - 否则不会调用 onStartCommand。
这就是我创建与 AlarmManager 一起使用的 PendingIntent 的方式:
Intent myIntent = new Intent( myContext, MyJobIntentService.class);
...
PendingIntent pendingIntent = PendingIntent.getService( mContext, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
myAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
关于我遗漏的任何想法?
最佳答案
你可以试试this推荐。此外,您可能需要检查您的 AndroidManifest.xml 是否具有 android.permission.BIND_JOB_SERVICE
权限。
关于android - 未在 JobIntentService 中调用 onHandleWork(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53872938/
我最近正在更新一个我正在使用 JobIntentService 而不是常规 IntentService 处理推送通知的应用程序,因为这似乎是处理此问题的正确方法在 Lollipop 之前的设备以及后期
我需要在我的应用程序运行时和启动时处理通过 AlarmManager 发布的 Intent 。我已经编写了 JobIntentService 的子类来处理 Intent ,但它没有按预期工作:没有调用
当使用 JobIntentService 时,我在使用 targetSDK 26 的 Android 8 上遇到了 SecurityException 崩溃。 这是来自 JobIntentServic
我目前正在从 Service 类扩展我的自定义服务实现。作为 Android-O 迁移的一部分,我想使用 JobIntentService。 目前我所有的逻辑都在服务的 onStartCommand
我有一个小部件。完成 SettingsActivity 从 Internet 加载数据并将其显示在 ListView 中。这适用于奥利奥之前和奥利奥设备。 但是以下两种行为不是由任何 Activity
我正在研究 Geofencing应用。 JobIntentService处理 GeofenceTransitions 的子类永远不会收到 Intent 。我每隔一分钟接收一次位置更新,然后创建一个新的
我是一名优秀的程序员,十分优秀!