我为工作管理器编写了代码,但运行时什么也没显示,也没有错误。
我经常搜索并阅读有关工作经理的所有问题,但不理解问题。
OneTimeWorkRequest uploadWorkRequest = new
OneTimeWorkRequest.Builder(UploadWorker.class)
.build();
WorkManager.getInstance().enqueue(uploadWorkRequest);
这是工人阶级:
public class UploadWorker extends Worker {
Context context;
@Override
public Result doWork() {
Toast.makeText(getApplicationContext(),"es",Toast.LENGTH_LONG).show();
final AlertDialog.Builder alertDialog=new
AlertDialog.Builder(getApplicationContext());
alertDialog.setTitle("Do You Want to Delete This Record");
alertDialog.setCancelable(false)
.setMessage("Click yes to delete")
.setPositiveButton("Yes", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).setNegativeButton("No", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog alertDialog1=alertDialog.create();
alertDialog1.show();
return Result.SUCCESS;
}
}
答案 0 :(得分:0)
您正在滥用WorkManager;您不应将其用于尝试中。尝试将doWork
方法中的代码移动到片段或活动中。