AlarmManager.RTC not working?

I changed AlarmController.java in ApiDemo a bit, so I want the alarm not to go out when the phone is sleeping using AlarmManager.RTC.

        Intent intent = new Intent(AlarmController.this, RepeatingAlarm.class);
        PendingIntent sender = PendingIntent.getBroadcast(AlarmController.this,
                0, intent, 0);

        // We want the alarm to go off 30 seconds from now.
        long firstTime = SystemClock.elapsedRealtime();
        firstTime += 15*1000;

        // Schedule the alarm!
        AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
        am.setRepeating(AlarmManager.RTC, //AlarmManager.ELAPSED_REALTIME_WAKEUP,
                        firstTime, 15*1000, sender);

The receiver code is as follows:

public class RepeatingAlarm extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        Log.d("DEBUG", "In RepeatingAlarm.onReceive, intent=" + intent);
        Toast.makeText(context, R.string.repeating_received, Toast.LENGTH_SHORT).show();
    }
}

I launched a modified application, but still see a lot of log messages, as shown below, after the phone went offline (the screen was black):

D / DEBUG (1390): In RepeatingAlarm.onReceive, intent = Intent {flg = 0x4 cmp = com.example.android.apis / .app.RepeatingAlarm (has additional features)}

This means that the AlarmManager.RTC flag does not work. Can someone tell me why?

Thank.

+3
source share
1 answer

elapsedRealtime, , , ELAPSED_REALTIME RTC.

, , , RTC, , , 1 1970 , , .

RTC, System.currentTimeMillis() Java Date Calendar. ELAPSED_REALTIME, SystemClock.elapsedRealtime().

+8

Source: https://habr.com/ru/post/1735159/


All Articles