After Nougat version the way back ground service is changed. If you want your background service to work, you can do as mentioned in the code below. In IntentService, the life cycle method onCreate() is called. And in this method add below code.
@Override
public void onCreate() {
super.onCreate();
int NOTIFICATION_ID = (int) (System.currentTimeMillis()%10000);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForeground(NOTIFICATION_ID, new Notification.Builder(this).build());
}
}
And when you are calling service, call your service via blow code
Intent intent = new Intent(context, FindNumberService.class);
intent.putExtras(bundle);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
}
else {
context.startService(intent);
}
Hope this will help you.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…