work/workmanager/src/main/java/androidx/work/impl/utils/CancelWorkRunnable.java
public static Runnable forAll(@NonNull final WorkManagerImpl workManagerImpl) {
        return new CancelWorkRunnable() {
            @Override
            public void run() {
                WorkDatabase workDatabase = workManagerImpl.getWorkDatabase();
                workDatabase.beginTransaction();
                try {
                    WorkSpecDao workSpecDao = workDatabase.workSpecDao();
                    List<String> workSpecIds = workSpecDao.getAllUnfinishedWork();
                    for (String workSpecId : workSpecIds) {
                        cancel(workManagerImpl, workSpecId);
                    }
                    workDatabase.setTransactionSuccessful();
                    // Update the preferences
                    new Preferences(workManagerImpl.getApplicationContext())
                            .setLastCancelAllTimeMillis(System.currentTimeMillis());
                } finally {
                    workDatabase.endTransaction();
                }
                // No need to call reschedule pending workers here as we just cancelled everything.
            }
        };
    }
/**
     * Creates a {@link CancelWorkRunnable} that cancels all work.
     *
     * @param workManagerImpl The {@link WorkManagerImpl} to use
     * @return A {@link Runnable} that cancels all work
     */
Creates a  CancelWorkRunnable that cancels all work.
@param workManagerImpl The  WorkManagerImpl to use
@return A  Runnable that cancels all work
Creates a CancelWorkRunnable that cancels all work . @param workManagerImpl The WorkManagerImpl to use @return A Runnable that cancels all work
public static Runnable forAll(@NonNull final WorkManagerImpl workManagerImpl) {
        return new CancelWorkRunnable() {
            @Override
            public void run() {
                WorkDatabase workDatabase = workManagerImpl.getWorkDatabase();
                workDatabase.beginTransaction();
                try {
                    WorkSpecDao workSpecDao = workDatabase.workSpecDao();
                    List<String> workSpecIds = workSpecDao.getAllUnfinishedWork();
                    for (String workSpecId : workSpecIds) {
                        cancel(workManagerImpl, workSpecId);
                    }
                    workDatabase.setTransactionSuccessful();
                    new Preferences(workManagerImpl.getApplicationContext())
                            .setLastCancelAllTimeMillis(System.currentTimeMillis());
                } finally {
                    workDatabase.endTransaction();
                }
            }
        };
    }
public static Runnable forAll ( @ NonNull final WorkManagerImpl workManagerImpl ) { return new CancelWorkRunnable ( ) { @ Override public void run ( ) { WorkDatabase workDatabase = workManagerImpl . getWorkDatabase ( ) ; workDatabase . beginTransaction ( ) ; try { WorkSpecDao workSpecDao = workDatabase . workSpecDao ( ) ; List < String > workSpecIds = workSpecDao . getAllUnfinishedWork ( ) ; for ( String workSpecId : workSpecIds ) { cancel ( workManagerImpl , workSpecId ) ; } workDatabase . setTransactionSuccessful ( ) ; new Preferences ( workManagerImpl . getApplicationContext ( ) ) . setLastCancelAllTimeMillis ( System . currentTimeMillis ( ) ) ; } finally { workDatabase . endTransaction ( ) ; } } } ; }
Creates a {@link CancelWorkRunnable} that cancels all work.
Creates a { @link CancelWorkRunnable } that cancels all work .
// Update the preferences // No need to call reschedule pending workers here as we just cancelled everything.