android-workmanager

How can create WorkerParameters

我怕爱的太早我们不能终老 提交于 2019-12-21 17:24:33
问题 Worker's Worker() is @Deprecated , so need use public Worker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); } but the WorkerParameters's constructor is @hide . so, how can create WorkerParameters instance? This library is the latest version of Android background task scheduling library, but this library has recently updated the API to mark the old creation method of the core class as discarded Now, I don't know how to create this core class,

Avoiding duplicating PeriodicWorkRequest from WorkManager

此生再无相见时 提交于 2019-12-21 13:02:23
问题 On Application start I want to start service that will work forever, but when user opens app again it duplicates. PeriodicWorkRequest.Builder sendDataBuilder = new PeriodicWorkRequest.Builder(SendConnectionMetricsWorker.class, Constants.REPEAT_TIME_INTERVAL_IN_HOURS, Constants.REPEAT_TIME_INTERVAL_UNITS) .setConstraints(new Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .build()); PeriodicWorkRequest periodicWorkRequest = sendDataBuilder .build(); WorkManager.getInstance

Is WorkerManager a realiable way to implement alarm/reminder feature in the app?

不打扰是莪最后的温柔 提交于 2019-12-21 07:36:06
问题 We notice that AlarmManagerCompat alone, isn't a reliable way to implement alarm/ reminder feature in our app, due to different AlarmManager behaviour in different version of OS. (For instance, Doze mode) Initially, we plan to use Evernote's android-job library, to help us implement alarm/ reminder feature in our app. However, along the way, we also notice that Google just release WorkerManager . So far, WorkerManager works well for us, when we run some one-time background jobs (Almost

WorkManager doWork callback is not received in Redmi and other custom Chinese ROM when device got rebooted and force closed the app

旧巷老猫 提交于 2019-12-21 06:17:22
问题 My app is not receiving push notification in Redmi phones while the app is in the background or it got killed by swiping. So I am trying to wake the phone by WorkManager which works on many phones except Redmi and other Chinese custom ROM phones. Here is my code of Worker class public class OpenTalkWorkManager extends Worker { @NonNull @Override public Result doWork() { Log.i("wake_up", "Waking up now: " + System.currentTimeMillis()); FirebaseUtils.getInstance().updateUserPresenceStatus

WorkManager doWork callback is not received in Redmi and other custom Chinese ROM when device got rebooted and force closed the app

一世执手 提交于 2019-12-21 06:17:04
问题 My app is not receiving push notification in Redmi phones while the app is in the background or it got killed by swiping. So I am trying to wake the phone by WorkManager which works on many phones except Redmi and other Chinese custom ROM phones. Here is my code of Worker class public class OpenTalkWorkManager extends Worker { @NonNull @Override public Result doWork() { Log.i("wake_up", "Waking up now: " + System.currentTimeMillis()); FirebaseUtils.getInstance().updateUserPresenceStatus

Any way to have initial delay for PeriodicWorkRequest

浪尽此生 提交于 2019-12-21 04:20:58
问题 For OneTimeWorkRequest , we can have setInitialDelay to specific the initial delay. However, there isn't such facility for PeriodicWorkRequest . Is there any reliable way to achieve so? One of the less reliable way, is to have a delayed OneTimeWorkRequest worker, to setup PeriodicWorkRequest . However, that's quite cumbersome, and create a possibility, where OneTimeWorkRequest may fail and not able to install PeriodicWorkRequest . 回答1: Since androidx.work:work-*:2.1.0 , PeriodicWorkRequests

Periodic daily work requests using WorkManager

我是研究僧i 提交于 2019-12-18 20:47:15
问题 How to properly use the new WorkManager from Android Jetpack to schedule a one per day periodic work that should do some action on a daily basis and exactly one time? The idea was to check if the work with a given tag already exists using WorkManager and to start a new periodic work otherwise. I've tried to do it using next approach: public static final String CALL_INFO_WORKER = "Call worker"; ... WorkManager workManager = WorkManager.getInstance(); List<WorkStatus> value = workManager

Why backup related process might cause Application's onCreate is not executed?

不打扰是莪最后的温柔 提交于 2019-12-18 18:47:11
问题 It is common to have Application class as follow public class WeNoteApplication extends MultiDexApplication { public static WeNoteApplication instance() { return me; } @Override public void onCreate() { super.onCreate(); me = this; During normal circumstance, Application 's onCreate will always be called before entry point Activity 's onCreate. public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState

Unable to set a custom worker factory in WorkManager

爷,独闯天下 提交于 2019-12-18 05:06:14
问题 I use this code to set my own worker factory: val daggerWorkerFactory = DaggerWorkerFactory(toInjectInWorker) val configuration = Configuration.Builder() .setWorkerFactory(daggerWorkerFactory) .build() WorkManager.initialize(context, configuration) After this code execution, I can get the WorkManager instance: val workManager = WorkManager.getInstance() The problem is that for every worker created after this point, my factory is never used. The default factory is used instead. I can see in

How do I run a ListenableWorker work on a background thread?

南楼画角 提交于 2019-12-18 04:24:44
问题 Since I need to perform work asynchronously in WorkManager, I need to use the ListenableWorker , which by default runs on the main (UI) thread. Since this work could be a long processing tasks that could freeze the interface, I wanted to perform it on a background thread. In the Working with WorkManager (Android Dev Summit '18) video, the Google engineer showed how to manually configure WorkManager to run works on a custom Executor , so I followed his guidance: 1) Disable the default