【问题标题】:Ibinder and JobintentServiceIbinder 和 JobintentService
【发布时间】:2019-06-25 04:23:11
【问题描述】:

我的问题很简单,但我一直在努力解决这个问题!

我有一个绑定服务调用 onBound() 方法:

    @Override
public IBinder onBind(Intent intent) {
    return null;
}

Unlikley,不可能将该实现与 JobIntentService 一起使用,因为它会抛出 JobServiceContext: Time-Out with binding service

当然,删除该覆盖方法不是解决方案,因为我无法删除它...

这是我的 JobIntenteservice

JobBoot.java

public class JobBoot extends JobIntentService {

public static final int JOB_ID = 0x01;

public static void enqueueWork(Context context, Intent work) {
    enqueueWork(context, BackgroundService.class, JOB_ID, work);
}

@Override
protected void onHandleWork(@NonNull Intent intent) {
    // your code
}}

我能做些什么来解决这个问题??

谢谢

【问题讨论】:

  • stackoverflow.com/a/46255491/415673 回答你的问题了吗?
  • 不幸的是,我没有,因为如果我删除 onBind 方法,我会收到错误“类必须是贴花抽象或包含抽象方法 onBind ()”
  • 当然,Ibinder 方法在 BackgroundServie.java 中

标签: java android


【解决方案1】:

在 JobBoot 类的静态方法 enqueueWork 中,它应该使用 JobBoot 而不是 BackgroundService。

public static void enqueueWork(Context context, Intent work) { enqueueWork(context, JobBoot.class, JOB_ID, work); }

在 JobBoot 的 onHandleWork

   protected void onHandleWork(@NotNull Intent intent) {

     // 
     Intent intent = new Intent(this, BackgroundService.class)
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
         startForegroundService(intent)
     } else {
         startService(intent)
     }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-05
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    • 2019-04-14
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多