Skip to content

Instantly share code, notes, and snippets.

View Suchiq's full-sized avatar

Suchi Bansal Suchiq

View GitHub Profile
@NonNull
@Override
public Result doWork() {
String taskDesc = getInputData().getString(TASK_DESC);
displayNotification("My Worker", taskDesc);
//setting output data
Data data = new Data.Builder()
.putString(TASK_DESC, "The conclusion of the task")
.build();
public class MyWorker extends Worker {
//a public static string that will be used as the key
//for sending and receiving data
public static final String TASK_DESC = "task_desc";
public MyWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
final TextView textView = findViewById(R.id.textViewStatus);
//Listening to the work status
WorkManager.getInstance().getWorkInfoByIdLiveData(workRequest.getId())
.observe(this, new Observer<WorkInfo>() {
@Override
public void onChanged(@Nullable WorkInfo workInfo) {
//Displaying the status into TextView
textView.append(workInfo.getState().name() + "\n");}
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//This is the subclass of our WorkRequest
final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(MyWorker.class).build();
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//This is the subclass of our WorkRequest
final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(MyWorker.class).build();
//A click listener for the button
//inside the onClick method we will perform the work
findViewById(R.id.buttonEnqueue).setOnClickListener(new View.OnClickListener() {
implementation "android.arch.work:work-runtime:1.0.0-alpha11"
public class MyWorker extends Worker {
public MyWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
/*
* This method is responsible for doing the work
* so whatever work that is needed to be performed
* we will put it here
*
* For example, here I am calling the method displayNotification()
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:valueFrom="1.0"
android:valueTo="0.0"
android:propertyName="alpha"
android:duration="0" />
<objectAnimator
android:valueFrom="-180"a
android:valueTo="0"
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"
app:cardElevation="7dp">
<RelativeLayout
android:id="@+id/card_back"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#551a8b">
AccessibilityChecks.enable()