This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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");} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation "android.arch.work:work-runtime:1.0.0-alpha11" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AccessibilityChecks.enable() |