I am newbie in android. I want to do some work everyday at a specific time. My work is to fetch one data from database and to show to the user. I used onReceive method to do that work.
I put below code to the OnCreate method
SharedPreferences prefs = getSharedPreferences("FIRST_TIME_LOGIN", MODE_PRIVATE);
String restoredText = prefs.getString("isFirstTime", null);
if (restoredText == null) {
SharedPreferences.Editor editor = getSharedPreferences("FIRST_TIME_LOGIN", MODE_PRIVATE).edit();
editor.putString("isFirstTime", "yes");
editor.commit();
Calendar calendar = Calendar.getInstance();
//calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 9);
calendar.set(Calendar.MINUTE, 35);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.AM_PM,Calendar.AM);
Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, alarmIntent, 0);
manager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
int interval = 1000*60*5;//calendar.getTimeInMillis()//AlarmManager.INTERVAL_DAY
manager.setRepeating(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis() ,AlarmManager.INTERVAL_HOUR , pendingIntent);
Toast.makeText(getApplicationContext(), "Alarm Set MainActivity", Toast.LENGTH_SHORT).show();
}
To check i used one hour interval. Problem is whenever i install my app ,instantly it fires the alarm where it should fire the alarm at 9.30AM.
What is the wrong in my code??