Merge pull request #5218 from Isira-Seneviratne/Use_ServiceCompat_stopForeground

Use ServiceCompat.stopForeground().
This commit is contained in:
Stypox 2020-12-19 14:05:44 +01:00 committed by GitHub
commit f59099395f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 6 deletions

View file

@ -25,6 +25,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.app.NotificationCompat;
import androidx.core.app.ServiceCompat;
import androidx.core.widget.TextViewCompat;
import androidx.fragment.app.FragmentManager;
import androidx.preference.PreferenceManager;
@ -695,7 +696,7 @@ public class RouterActivity extends AppCompatActivity {
@Override
public void onDestroy() {
super.onDestroy();
stopForeground(true);
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE);
if (fetcher != null) {
fetcher.dispose();
}

View file

@ -30,6 +30,7 @@ import android.os.IBinder
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.ServiceCompat
import androidx.preference.PreferenceManager
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Flowable
@ -147,7 +148,7 @@ class FeedLoadService : Service() {
private fun stopService() {
disposeAll()
stopForeground(true)
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
notificationManager.cancel(NOTIFICATION_ID)
stopSelf()
}

View file

@ -31,6 +31,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.app.ServiceCompat;
import org.reactivestreams.Publisher;
import org.schabi.newpipe.R;
@ -162,7 +163,7 @@ public abstract class BaseImportExportService extends Service {
protected void postErrorResult(final String title, final String text) {
disposeAll();
stopForeground(true);
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE);
stopSelf();
if (title == null) {

View file

@ -15,6 +15,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.core.app.ServiceCompat;
import androidx.core.content.ContextCompat;
import org.schabi.newpipe.MainActivity;
@ -188,7 +189,7 @@ public final class NotificationUtil {
}
void cancelNotificationAndStopForeground(final Service service) {
service.stopForeground(true);
ServiceCompat.stopForeground(service, ServiceCompat.STOP_FOREGROUND_REMOVE);
if (notificationManager != null) {
notificationManager.cancel(NOTIFICATION_ID);

View file

@ -25,6 +25,7 @@ import android.os.IBinder;
import android.os.Message;
import android.os.Parcelable;
import androidx.core.app.ServiceCompat;
import androidx.core.content.ContextCompat;
import androidx.preference.PreferenceManager;
import android.util.Log;
@ -235,7 +236,7 @@ public class DownloadManagerService extends Service {
Log.d(TAG, "Destroying");
}
stopForeground(true);
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE);
if (mNotificationManager != null && downloadDoneNotification != null) {
downloadDoneNotification.setDeleteIntent(null);// prevent NewPipe running when is killed, cleared from recent, etc
@ -363,7 +364,7 @@ public class DownloadManagerService extends Service {
if (state) {
startForeground(FOREGROUND_NOTIFICATION_ID, mNotification);
} else {
stopForeground(true);
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE);
}
manageLock(state);