Java Code Examples for androidx.work.WorkManager#initialize()

The following examples show how to use androidx.work.WorkManager#initialize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobProxyWorkManager.java    From android-job with Apache License 2.0 6 votes vote down vote up
private WorkManager getWorkManager() {
    // don't cache the instance, it could change under the hood, e.g. during tests
    WorkManager workManager;
    try {
        workManager = WorkManager.getInstance(mContext);
    } catch (Throwable t) {
        workManager = null;
    }
    if (workManager == null) {
        try {
            WorkManager.initialize(mContext, new Configuration.Builder().build());
            workManager = WorkManager.getInstance(mContext);
        } catch (Throwable ignored) {
        }
        CAT.w("WorkManager getInstance() returned null, now: %s", workManager);
    }

    return workManager;
}
 
Example 2
Source File: FlutterUploaderInitializer.java    From flutter_uploader with MIT License 5 votes vote down vote up
@Override
public boolean onCreate() {
  int maximumConcurrentTask = getMaxConcurrentTaskMetadata(getContext());
  WorkManager.initialize(
      getContext(),
      new Configuration.Builder()
          .setExecutor(Executors.newFixedThreadPool(maximumConcurrentTask))
          .build());
  return true;
}
 
Example 3
Source File: GndApplication.java    From ground-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate() {
  if (BuildConfig.DEBUG) {
    Timber.d("DEBUG build config active; enabling debug tooling");

    // Debug bridge for Android applications. Enables network and database debugging for the app
    // accessible under chrome://inspect in Chrome desktop browser. Must be done before calling
    // setStrictMode().
    Stetho.initializeWithDefaults(this);

    // Log failures when trying to do work in the UI thread.
    setStrictMode();
  }

  super.onCreate();

  // Enable RxJava assembly stack collection for more useful stack traces.
  RxJava2Debug.enableRxJava2AssemblyTracking(new String[] {getClass().getPackage().getName()});

  // Prevent RxJava from force-quitting on unhandled errors.
  RxJavaPlugins.setErrorHandler(RxDebug::logEnhancedStackTrace);

  // Set custom worker factory that allow Workers to use Dagger injection.
  // TODO(github.com/google/dagger/issues/1183): Remove once Workers support injection.
  WorkManager.initialize(
      this, new Configuration.Builder().setWorkerFactory(workerFactory).build());

  if (BuildConfig.DEBUG) {
    Timber.plant(new Timber.DebugTree());
  } else {
    Timber.plant(new CrashReportingTree());
  }
}
 
Example 4
Source File: FlutterDownloaderInitializer.java    From flutter_downloader with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean onCreate() {
    int maximumConcurrentTask = getMaxConcurrentTaskMetadata(getContext());
    WorkManager.initialize(getContext(), new Configuration.Builder()
            .setExecutor(Executors.newFixedThreadPool(maximumConcurrentTask))
            .build());
    return true;
}