android - Why does the background service stops while running? -
i have background service in android application.in thread listening recent tasks running frequently.my service overrides both oncreate()
, onstartcommand()
methods. when tried open applications gallery
,camera
etc..., service stopped.it calls oncreate()
method , not ondestroy()
or onstartcommand()
.i tried override onlowmemory() in service logs nothing.the application saved internally specifying
android:installlocation="internalonly"
in manifest file.
note: issue noticed on micromax a54 2.3.5
.
why background service stops sometimes? there solution issue?
public class myservice extends service { public myservice() { } @override public int onstartcommand(intent intent, int flags, int startid) { try { if(intent != null){ //...... } } catch (throwable e) { } return start_sticky; } @override public void ondestroy() { super.ondestroy(); } @override public void oncreate() { super.oncreate(); //...... } @override public ibinder onbind(intent intent) { return null; } }
and start service this
intent intent = new intent(getapplicationcontext(), myservice.class); getapplicationcontext().startservice(intent);
android can stop service @ time reason. typical reason low memory (killing service give memory elsewhere), i've seen @ least few devices kill them every x hours regardless. there no way ensure run. best can have activities try start service (in case isn't running), write service can reload needed data, , set start_sticky if has enough memory framework restart later.
Comments
Post a Comment