I am using work manager Onetime Request to perform the task. First the alarm manager gets call in given frequency and from alarm manager receiver class, work manager class gets called. All code was working fine, but suddenly the work manager doWork is not getting called. Flow is coming till alarm manager receiver but not proceeding further.
Alarm Manager Receiver class
public class WorkAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
final String TAG = "WorkAlarmReceiver";
if (BuildConfig.DEBUG) {
Log.i(TAG, "onReceive: intent=" + intent);
}
OneTimeWorkRequest startWork = new OneTimeWorkRequest.Builder(WorkManagerForTools.class).build();
WorkManager.getInstance(context).enqueueUniqueWork("Validate Tool", ExistingWorkPolicy.APPEND_OR_REPLACE , startWork);
}
This Receiver is calling fine in given time interval
//checking if alarm is working with pendingIntent
Intent workIntent = new Intent(mContext,
WorkAlarmReceiver.class)
.setAction(Long.toString(System.currentTimeMillis()
PendingIntent workPendingIntent = PendingIntent.getBroadcast(mContext, 1001,
workIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Log.e(TAG, "New data of pending intent: " + workSpecId + " local work id, " + localWorkId +
" tools id list " + updatedMobileAppToolIds);
if(BuildConfig.DEBUG) {
Log.d(TAG, "New data of pending intent: " + workSpecId + " local work id, " + localWorkId +
" tools id list " + updatedMobileAppToolIds);
}
boolean isWorking = (PendingIntent.getBroadcast(mContext, 1001, workIntent, PendingIntent.FLAG_NO_CREATE) != null);//just changed the flag
if (isWorking) {
alarmManager.cancel(workPendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
10 * (minFrequency / 10), workPendingIntent);
} else {
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
10 * (minFrequency / 10), workPendingIntent);
}
The alarm manager receiver class then call workmanager class. Here is the work manager class
@SuppressLint("WrongThread")
@NonNull
@Override
public Result doWork() {
// Code to be execute
}
Any help on this Appreciated.