work/workmanager/src/main/java/androidx/work/impl/utils/CancelWorkRunnable.java
public static Runnable forName(
            @NonNull final String name,
            @NonNull final WorkManagerImpl workManagerImpl) {
        return new CancelWorkRunnable() {
            @WorkerThread
            @Override
            public void run() {
                WorkDatabase workDatabase = workManagerImpl.getWorkDatabase();
                workDatabase.beginTransaction();
                try {
                    WorkSpecDao workSpecDao = workDatabase.workSpecDao();
                    List<String> workSpecIds = workSpecDao.getUnfinishedWorkWithName(name);
                    for (String workSpecId : workSpecIds) {
                        cancel(workManagerImpl, workSpecId);
                    }
                    workDatabase.setTransactionSuccessful();
                } finally {
                    workDatabase.endTransaction();
                }
                reschedulePendingWorkers(workManagerImpl);
            }
        };
    }
/**
     * Creates a {@link CancelWorkRunnable} that cancels work labelled with a specific name.
     *
     * @param name The name to cancel
     * @param workManagerImpl The {@link WorkManagerImpl} to use
     * @return A {@link Runnable} that cancels work labelled with a specific name
     */
Creates a  CancelWorkRunnable that cancels work labelled with a specific name.
@param name The name to cancel
@param workManagerImpl The  WorkManagerImpl to use
@return A  Runnable that cancels work labelled with a specific name
Creates a CancelWorkRunnable that cancels work labelled with a specific name . @param name The name to cancel @param workManagerImpl The WorkManagerImpl to use @return A Runnable that cancels work labelled with a specific name
public static Runnable forName(
            @NonNull final String name,
            @NonNull final WorkManagerImpl workManagerImpl) {
        return new CancelWorkRunnable() {
            @WorkerThread
            @Override
            public void run() {
                WorkDatabase workDatabase = workManagerImpl.getWorkDatabase();
                workDatabase.beginTransaction();
                try {
                    WorkSpecDao workSpecDao = workDatabase.workSpecDao();
                    List<String> workSpecIds = workSpecDao.getUnfinishedWorkWithName(name);
                    for (String workSpecId : workSpecIds) {
                        cancel(workManagerImpl, workSpecId);
                    }
                    workDatabase.setTransactionSuccessful();
                } finally {
                    workDatabase.endTransaction();
                }
                reschedulePendingWorkers(workManagerImpl);
            }
        };
    }
public static Runnable forName ( @ NonNull final String name , @ NonNull final WorkManagerImpl workManagerImpl ) { return new CancelWorkRunnable ( ) { @ WorkerThread @ Override public void run ( ) { WorkDatabase workDatabase = workManagerImpl . getWorkDatabase ( ) ; workDatabase . beginTransaction ( ) ; try { WorkSpecDao workSpecDao = workDatabase . workSpecDao ( ) ; List < String > workSpecIds = workSpecDao . getUnfinishedWorkWithName ( name ) ; for ( String workSpecId : workSpecIds ) { cancel ( workManagerImpl , workSpecId ) ; } workDatabase . setTransactionSuccessful ( ) ; } finally { workDatabase . endTransaction ( ) ; } reschedulePendingWorkers ( workManagerImpl ) ; } } ; }
Creates a {@link CancelWorkRunnable} that cancels work labelled with a specific name.
Creates a { @link CancelWorkRunnable } that cancels work labelled with a specific name .