There is an application that regularly makes a request to the server using the AlarmManager, with a specific response from the server showing AlertDialog. When the onReceive method is executed, if the AlertDialog on the screen closes and another request is executed, if the request is a positive window opens again. After a couple of restarts of the AlertDialog, the onReceive method is no longer running.
private void RegisterAlarmBroadcast() { mReceiver = new BroadcastReceiver() { // private static final String TAG = "Alarm Example Receiver"; @Override public void onReceive(Context context, Intent intent) { if (isStopped){ UnregisterAlarmBroadcast(); } if (alarm != null) { if (alarm.isShowing()) { DialogStop(); } } setAlarm(delay, pendingIntent); new XmlSending().execute(msgGetWarningAlarm); } }; registerReceiver(mReceiver, new IntentFilter("sample")); pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, new Intent("sample"), 0); alarmManager = (AlarmManager)(this.getSystemService(Context.ALARM_SERVICE)); setAlarm(delay, pendingIntent); } private void setAlarm(int delayInMillis, PendingIntent sender){ final int SDK_INT = Build.VERSION.SDK_INT; long timeInMillis = (System.currentTimeMillis() + delayInMillis) / 1000 * 1000; //> example if (SDK_INT < Build.VERSION_CODES.KITKAT) { alarmManager.set(AlarmManager.RTC_WAKEUP, timeInMillis, sender); } else if (Build.VERSION_CODES.KITKAT <= SDK_INT && SDK_INT < Build.VERSION_CODES.M) { alarmManager.setExact(AlarmManager.RTC_WAKEUP, timeInMillis, sender); } else if (SDK_INT >= Build.VERSION_CODES.M) { alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, timeInMillis, sender); } Toast.makeText(this, "New alarm!!!", Toast.LENGTH_SHORT).show(); } private void UnregisterAlarmBroadcast() { alarmManager.cancel(pendingIntent); getBaseContext().unregisterReceiver(mReceiver); } Tell me how to properly implement this process? The information in the AlertDialog can change because I haven't figured out how to restart it, but it is restarted only a couple of times, and then hangs without the onReceive method.