新手,我有这个功能setAlarm
:
public void setAlarm(){
SharedPreferences sa=PreferenceManager.getDefaultSharedPreferences(getBaseContext());
int hr=sa.getInt("alarmhour", 6);
int mn=sa.getInt("alarmminute", 0);
String st1=sa.getString("alarmstatus", "Alarm Disabled");
if(st1.equals("Alarm Enabled"))
{
AlarmManager ala = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent inte = new Intent(this, epicalarm.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, inte, 0);
Calendar time = Calendar.getInstance();
time.set(Calendar.HOUR_OF_DAY, hr);
time.set(Calendar.MINUTE, mn);
time.set(Calendar.SECOND, 0);
ala.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pi);
}
}
每次我调用该函数setAlarm
时,都会调用该onReceive
方法并显示警报。为什么?