java - run Service even if android app is closed -
my task run service if app closed.
my service class:
public class myservice extends service { public int onstartcommand(intent intent, int flags, int startid) { audiomanager am; am= (audiomanager) this.getsystemservice(context.audio_service); if(am.getringermode() == audiomanager.ringer_mode_normal) am.setringermode(audiomanager.ringer_mode_silent); else am.setringermode(audiomanager.ringer_mode_normal); minute minute = new minute(); calendar cal = calendar.getinstance(); alarmmanager alarms ; intent activate = new intent(this, myservice.class); pendingintent alarmintent = pendingintent.getservice(this, 0, activate, 0); alarms = (alarmmanager) this.getsystemservice(context.alarm_service); cal.set(calendar.hour_of_day, 00); cal.set(calendar.minute, minute.minute); cal.set(calendar.second, 00); alarms.set(alarmmanager.rtc_wakeup, cal.gettimeinmillis(), alarmintent); toast.maketext(this, "checkonstart", toast.length_long).show(); return service.start_sticky; } }
in activity:
intent activate = new intent(this, myservice.class); startservice(activate);
i try use foreground service it's doesnt me when kill app service closed, should keep service running after app killed?
Comments
Post a Comment