This works great:
Intent intent = new Intent(HelloAndroid2.this, AlarmReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(HelloAndroid2.this, 0, intent, PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (12 * 1000), pendingIntent);
This does not work. I hear only the alarm.
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (12 * 1000), 3 * 1000, pendingIntent);
I tried this too, no luck:
Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.SECOND, 5); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 7000, pendingIntent);
What is the problem?
From the PendingIntent doc for FLAG_ONE_SHOT:
this PendingIntent can only once. If set, after send () is called on it, it will be automatically canceled for you and any future attempt to send through it will fail.
So, after pendingIntent is launched for the first time, it will be canceled, and the next attempt to send it through the alarm manager will fail
Try using FLAG_UPDATE_CURRENT
Look at your code samples in order:
AlarmManager.set - , , . AlarmManager.set, , , ( PendingIntent).
. PendingIntent , , .
, 3 , BroadcastReceiver, .
, . onReceive() . , , , , ( ) . , - , , , - .
, , android.os.Handler - , , AlarmManager, .
Source: https://habr.com/ru/post/1785617/More articles:Android equivalent of IBActions and IBOutlets - androidThe best structure for a small 3D application - c #Exception when using HttpClient to execute GET after POST - javaИзвлечение текста с помощью NSRegularExpression - regexRenaming a table prefix using wildcards - sqlHow to make mocks for web tests? - asp.netHow can I sort by multiple fields in LINQ? - linqScaling with LinearLayout - androidBroadcastReceiver called, but PhoneStateListener not called - androidwhat is the difference between sleeping 2.X and sleeping 3.0 - hibernateAll Articles