krunalpatel3 / WorkManager-Example-Andorid

How to use WorkManager in Android.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Workmanager without activity

kiransnagaraj opened this issue · comments

Hi Krunalpatel I tried to run workmanager without activity. From application instance I tried to run workmanager but it's nit happening. Please suggest better way to achieve this issue.
Thanks in advance

means you want to start workmanager without launching acitvity?

so you want to start workmanager on Application start.

Hello Kiran

you are using periodic worker like this:-

mPeriodicWorkRequest = new PeriodicWorkRequest.Builder(MyPeriodicWork.class,
18, TimeUnit.MINUTES)
.addTag("periodicWorkRequest")
.build();

here every 18 MINUTES your backgound work will start.

do you want to run backgound task periodic?

so the work manager should also run even if the battery is low and run when the device gets internet connection.

i think there will be no problem just to run work manager using transparent activity.

But if you are using PeriodicWorkRequest than you don't have to handle boot complete or restart or shutdown device it is automatically handle by WorkManager.When device get's reboot automatically WorkManager schedule the your works.