java - Start AlarmManager on button click -


i want start alarmanager when button pressed. problem is: starts when start app :/

my code:

public void schedulealarm()     {               int time = 10 * 1000;              intentalarm = new intent(this, alarmreciever.class);              alarm = (alarmmanager) getsystemservice(context.alarm_service);             alarm.setrepeating(alarmmanager.rtc_wakeup, time, time, pendingintent.getbroadcast(this,1,  intentalarm, pendingintent.flag_update_current));      } 

and try call in onclicklistener of button. starts beginning of activity :/

can me?

thanks posting code. try this:

public static string alarm_to_set = "alrmtosend"; yourbutton.setonclicklistener(new onclicklistener(){ public void onclick(view view){      int time = 10 * 1000;      intentalarm = new intent(alarm_to_set);      alarm = (alarmmanager) getsystemservice(context.alarm_service);     pendingintent pintent = pendingintent.getbroadcast(this, 0, intentalarm, 0)     alarm.setrepeating(alarmmanager.rtc_wakeup, time, time, pintent);     } }); 

your broadcast receiver should registered in manifest.xml file as:

<receiver android:name=".alarmrecieverclass"> <intent-filter> <action android:name="alrmtosend" /> </intent-filter> </receiver> 

Comments