Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.workmanager;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.work.Constraints;
- import androidx.work.NetworkType;
- import androidx.work.PeriodicWorkRequest;
- import androidx.work.WorkManager;
- import android.os.Bundle;
- import java.util.concurrent.TimeUnit;
- public class MainActivity extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Constraints constraints=new Constraints.Builder()
- .setRequiresDeviceIdle(true)
- .setRequiresCharging(true)
- .setRequiresBatteryNotLow(true)
- .build();
- PeriodicWorkRequest periodicWorkRequest=new PeriodicWorkRequest.Builder(MyWork.class,16, TimeUnit.MINUTES)
- .addTag("Periodic")
- .setConstraints(constraints)
- .build();
- WorkManager.getInstance(this).enqueue(periodicWorkRequest);
- }
- }
Add Comment
Please, Sign In to add comment