Android Service, do we have to use startService or BindService? -


i developping musicplayer app, , use local service make mediaplayer run in background. seems can either send intent start service or bind service. understand point of startservice, leave running , send intent stopservice, , bindservice, ibinder communicate service. however, i'm wondering what's point of doing this? have send intents make work? if retrieve static instance of service, , directly call methods, can implement both start , communicate it.

i found example of not using startservice nor bindservice, works simple musicplayer.

the fragment calls service: https://github.com/zacharytamas/spotify-sampler/blob/master/app/src/main/java/com/zacharytamas/spotifysampler/ui/playerfragment.java

the service class: https://github.com/zacharytamas/spotify-sampler/blob/master/app/src/main/java/com/zacharytamas/spotifysampler/services/playerservice.java

however, i'm wondering what's point of doing this?

to have service running, tell os "hey, doing work here on behalf of user, please let process live bit longer".

this covered in the documentation.

do have send intents make work?

yes.

if retrieve static instance of service, , directly call methods, can implement both start , communicate it.

then merely java object, , there no point in inheriting service. also, means process live less time when ui not in foreground.

i found example of not using startservice nor bindservice, works simple musicplayer.

the service started, via startservice(), in artistsearchactivity. until done, service not exist, , singleton null.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -