Pass startId to stopSelf

pull/795/head
Alex Baker 5 years ago
parent 2fbc356e84
commit 8debdfac91

@ -19,21 +19,22 @@ public abstract class InjectingService extends Service {
public void onCreate() {
super.onCreate();
startForeground(getNotificationId(), buildNotification());
startForeground();
disposables = new CompositeDisposable();
inject(((InjectingApplication) getApplication()).getComponent().plus(new ServiceModule()));
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
startForeground(getNotificationId(), buildNotification());
startForeground();
inject(((InjectingApplication) getApplication()).getComponent().plus(new ServiceModule()));
disposables =
new CompositeDisposable(
Completable.fromAction(this::doWork)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::stopSelf));
disposables.add(
Completable.fromAction(this::doWork)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> stopSelf(startId)));
return Service.START_NOT_STICKY;
}
@ -47,6 +48,10 @@ public abstract class InjectingService extends Service {
disposables.dispose();
}
private void startForeground() {
startForeground(getNotificationId(), buildNotification());
}
protected abstract int getNotificationId();
protected abstract int getNotificationBody();

@ -1,6 +1,7 @@
package org.tasks.jobs;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.andlib.utility.AndroidUtilities.assertNotMainThread;
import android.content.Intent;
import android.os.IBinder;
@ -39,7 +40,9 @@ public class NotificationService extends InjectingService {
}
@Override
protected void doWork() {
protected synchronized void doWork() {
assertNotMainThread();
try {
if (!preferences.isCurrentlyQuietHours()) {
List<? extends NotificationQueueEntry> overdueJobs = notificationQueue.getOverdueJobs();

Loading…
Cancel
Save