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?

you can use foreground service. check tutorial this , this


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -