-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckActivity.java
More file actions
54 lines (46 loc) · 1.65 KB
/
CheckActivity.java
File metadata and controls
54 lines (46 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.manoj.workmanager;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkInfo;
import androidx.work.WorkManager;
import java.util.concurrent.TimeUnit;
/**
* @Author Manoj Suthar
* WorkManager created on 15/10/2019
* {@link MyWorker}
*/
public class CheckActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
compareDateWithServer();
}
private void compareDateWithServer() {
/*check if(date is matched)
* {
* setBackgroundTask();
* }
* */
}
private void setBackgroundTask() {
/**
* after 48 hours notification will be display.
* */
OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(MyWorker.class)
.setInitialDelay(48, TimeUnit.HOURS)
.build();
WorkManager.getInstance(getApplicationContext()).enqueue(request);
WorkManager.getInstance(getApplicationContext()).getWorkInfoByIdLiveData(request.getId()).observe(this, new Observer<WorkInfo>() {
@Override
public void onChanged(WorkInfo workInfo) {
/*After you enqueue your work, WorkManager allows you to check on
its status. This information is available in a WorkInfo object,
which includes the id of the work, its tags, its current State,
and any output data.*/
}
});
}
}