Local Service Binding in Android - To use... or not to use? -
so i'm working local service , i'd have activity send service commands. besides start , stop, i'd pause, or restart command activity service performing (the commands aren't important here, giving them examples.
i think binding service correct way this, i'm unsure of 2 things.
the android docs unbinding service kill it. if want service run in background... when activity oncreate()s want bind service (to control it/send commands) , ondestroy() i'd unbind activity service, keep service running.
i'm having trouble understanding excerpt big nerd ranch book on android development
this pattern looks exciting. place in android enables 1 android component directly talk another. not recommend it, though. since services singletons, using them way provides no major benefits on using singleton instead.
is telling me bind api makes things little complicated use local service?
the android docs unbinding service kill it.
more accurately, when call unbindservice(), if there no other outstanding bindings, , nothing called startservice() on service have running way, service destroyed.
what if want service run in background... when activity oncreate()s want bind service (to control it/send commands) , ondestroy() i'd unbind activity service, keep service running.
you have use both startservice() (to better control duration of service) , bindservice() then. and, if you're doing sending commands, i'd skip bindservice() outright , send commands via startservice().
i'm having trouble understanding excerpt big nerd ranch book on android development
the last quoted sentence is... odd.
is telling me bind api makes things little complicated use local service?
that's reasonable interpretation of quoted passage.
personally, find binding pain in various body parts, more it's worth local services. service important, indication os doing background work worth keeping process around bit longer. i'll use command pattern , event buses on local binding. binding state, state needs managed respect configuration changes. retained fragments make easier used be, it's still aggravating.
the binding pattern more important remote services, client , service in separate apps. while introduces whole host of new , exciting problems, there many ipc options in android, , remote services offer options difficult-to-impossible implement using other ipc options.
Comments
Post a Comment