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

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

Loading…
Cancel
Save