Android JobIntentService未调用手工
我不熟悉服务,决定使用JobIntentService,因为我的应用程序必须支持API 21+,但当我在API 28+上启动服务时,它无法正常工作 我发现当我使用Android JobIntentService未调用手工,android,intentservice,android-jobscheduler,Android,Intentservice,Android Jobscheduler,我不熟悉服务,决定使用JobIntentService,因为我的应用程序必须支持API 21+,但当我在API 28+上启动服务时,它无法正常工作 我发现当我使用Contextcompat.startForegroundService() 我的代码: 我的活动 Intent-Intent=新的Intent(这个,MyService.class); intent.putExtra(“fileTitle”,popup.name); ContextCompat.startForegroundServi
Contextcompat.startForegroundService()
我的代码:
我的活动
Intent-Intent=新的Intent(这个,MyService.class);
intent.putExtra(“fileTitle”,popup.name);
ContextCompat.startForegroundService(此,意图);
我的服务
@Override
public void onCreate() {
super.onCreate();
MyLog(this, "SERVICE ONCREATE", "SERVICE");
createNotificationChannel();
initNotification();
startForeground(NOTIFICATION_ID, nBuilder.build());
}
为了结束这一主题,以下是我如何使其工作的: 我的活动
Intent-Intent=新的Intent(这个,MyService.class);
intent.putExtra(“fileTitle”,popup.name);
ContextCompat.startForegroundService(此,意图);
我的服务
@Override
public void onCreate() {
super.onCreate();
MyLog(this, "SERVICE ONCREATE", "SERVICE");
createNotificationChannel();
initNotification();
startForeground(NOTIFICATION_ID, nBuilder.build());
}
@覆盖
public void onCreate(){
super.onCreate();
//API 26+中通知通道的初始化&显示初始化通知
createNotificationChannel();
初始化通知();
}
@凌驾
受保护的无效onHandleIntent(@Nullable Intent){
if(intent!=null&&isPostorEqualOS(Build.VERSION\u CODES.O)){
startForeground(通知ID,nBuilder.build());
}
}