I have set the repeat time to 5 seconds. The first toast appears after 5 seconds, but all the next once repeat after 1 minute.
I tried the code with setRepeating() as well, it still doesn't work.
here is my code:
public void constructJob(){
Intent alertIntent = new Intent(this, AlarmManagerService.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
this, 0,
alertIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(
AlarmManager.RTC_WAKEUP,
GregorianCalendar.getInstance().getTimeInMillis(),
repeatTime(),
pendingIntent
);
}
public long repeatTime(){
return 5000;
}
AlarmManagerService.java
public class AlarmManagerService extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "5 seconds have passed",
Toast.LENGTH_SHORT).show();
}