1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 11:02:35 +01:00

Use ServiceCompat.stopForeground().

This commit is contained in:
Isira Seneviratne 2020-12-19 16:52:17 +05:30
parent 467dacd35a
commit 0fe3fe7594
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);