android - Alarm won't stop ringing without killing the app -


i'm trying add alarm app i'm working on, stupid reason, once alarm ringing can't switch off without killing app.

the alarm activated togglebutton. if it's on, alarm ring @ scheduled time, , when it's off, won't...or @ least, it's not supposed to.

here's onclick code togglebutton:

@onclick(r.id.alarmtoggle2) protected void onalarmtoggleclicked(){     if(alarmtoggle.ischecked()){         alarmtimetext.settextcolor(color.green);         alarmtimetext.setvisibility(view.visible);         //switch on alarm         calendar calendar = calendar.getinstance();         calendar.settimeinmillis(system.currenttimemillis());         calendar.set(calendar.hour_of_day, alarmhour);         calendar.set(calendar.minute, alarmminute);          //it's time set off alarm         log.d(tag, "alarm");         alarmreceiverintent = new intent(remindersactivity.instance(),                 alarmreceiver.class);         broadcastintent = pendingintent.getbroadcast(getcontext(), alarmid,                 alarmreceiverintent, 0);         //rtc means alarm won't used if device asleep, rtc_wakeup means         //that will.         alarmmanager.set(alarmmanager.rtc_wakeup, calendar.gettimeinmillis(), broadcastintent);         alarmmanager.setrepeating(alarmmanager.rtc_wakeup, calendar.gettimeinmillis(),                 alarmmanager.interval_day, broadcastintent);     } else {         log.d(tag, "cancel alarm");         alarmtimetext.setvisibility(view.invisible);         alarmmanager.cancel(broadcastintent);         alarmtext.settext("");     } } 

and here's code of alarmreceiver class's onreceive() method:

    public void onreceive(context context, intent intent) {         //this update ui message         remindersactivity inst = remindersactivity.instance();         //sets content of alarmtext in remindersfragment         inst.setalarmtext("alarm! wake up! wake up!");          //this sound alarm tone         //this sound alarm once, if wish         //raise alarm in loop continuously use mediaplayer , setlooping(true)         uri alarmuri = ringtonemanager.getdefaulturi(ringtonemanager.type_alarm);         if (alarmuri == null) {             alarmuri = ringtonemanager.getdefaulturi(ringtonemanager.type_notification);         }         ringtone ringtone = ringtonemanager.getringtone(context, alarmuri);         ringtone.play();          componentname comp = new componentname(context.getpackagename(),             alarmservice.class.getname());         startwakefulservice(context, (intent.setcomponent(comp)));         setresultcode(activity.result_ok);     } 

i've since come solution: ringtone static variable of alarmreceiver, , how stop alarm ringing:

if(!alarmtoggle.ischecked()) {     //stop alarm ringing     if(alarmreceiver.ringtone.isplaying())         alarmreceiver.ringtone.stop();     alarmtimetext.setvisibility(view.invisible);     alarmmanager.cancel(broadcastintent);     alarmtext.settext(""); } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -