Search code examples
androidalarmmanager

How to avoid alarm trigger at time of set?


I am setting alarm with an interval of 2 hours. It work very perfect but the problem is, at the time of set it trigger the alarm. It don't have to trigger alarm at time of set rest is all ok.

        Intent _myIntent = new Intent(activity, MyReceiverStartPush.class);
        _myIntent.putExtra("msg", "Feed");

        PendingIntent _myPendingIntent = PendingIntent.getBroadcast(
                activity, 0, _myIntent, 0);
        AlarmManager _myAlarmManager = (AlarmManager) activity
                .getSystemService(Service.ALARM_SERVICE);

        _myAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
                System.currentTimeMillis(), (AlarmManager.INTERVAL_HOUR)
                        * 2, _myPendingIntent);

Solution

  • Instead of using System.currentTimeMillis() (which is the reason) you should use System.currentTimeMillis() + 2H there