Singleton Service ???

Showing 1-9 of 9 messages
Singleton Service ??? MobDev 2/11/10 8:09 AM
Hi,

I'd like to know if it's possible to create a Singelton Service
throughout an application ?
Let's say I'd like to cerate a Service to play some mp3... I'd like it
to be a Singleton, we don't want two mp3 tracks playing through each
other (well maybe some would want that, but in my case I'm not making
a DJ app) :P
Also this Service should be somewhat dynamic as in there should be
some interface so that I can stop, pauze and play the mp3 file/
stream...
Now I have a couple of questions :
- is this feasable ?
- should I be using a Service or something else ?
- how can an interface be set up inbetween an application and a
service so that I can start, stop, pauze stuff ?
- can there be something like a Singleton Service ?

Thanks in advance for any help !

Re: [android-developers] Singleton Service ??? Mark Murphy 2/11/10 8:11 AM
> I'd like to know if it's possible to create a Singelton Service
> throughout an application ?

Services are singletons by their very nature.

--
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html


Re: Singleton Service ??? MobDev 2/11/10 8:19 AM
well,
thats a good thing especially in my situation :D
Now my next most prioritized question, can I communicate with a
Service ?
Are there some kind of interfaces for that ?
Btw, you are a fast responder Mark ;)
Thanks for your interest and time :D

On 11 feb, 17:11, "Mark Murphy" <mmur...@commonsware.com> wrote:
> > I'd like to know if it's possible to create a Singelton Service
> > throughout an application ?
>
> Services are singletons by their very nature.
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com

> Android App Developer Books:http://commonsware.com/books.html

Re: [android-developers] Re: Singleton Service ??? Mark Murphy 2/11/10 8:25 AM
> Now my next most prioritized question, can I communicate with a
> Service ?

Absolutely.

> Are there some kind of interfaces for that ?

The SDK samples will demonstrate the local binding pattern. You can also
find an example of that here:

http://github.com/commonsguy/cw-android/tree/master/Service/WeatherPlus/

--
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html


Re: [android-developers] Re: Singleton Service ??? Dianne Hackborn 2/11/10 9:41 AM
Or use startService() to send commands to it.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en



--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Re: Singleton Service ??? MobDev 2/23/10 2:44 AM
actually I had a question regarding this...
I made a service which plays an MP3, so it uses a single instance (in
the whole service) of MediaPlayer..
Still I noticed (by mistake because the Service didn't get closed
while exiting my main Activity) that the Service obviously kept
running, but when I restarted my app it created another Service which
also could play the MP3, thus creating a "mixing" effect, having the
same MP3 playing double... The second one I could stop through my App
but the first "lost" one couldn't be stopped...
To me this doesn't look like a Singleton's behaviour, I actually have
two seperate entities of a Service running in the system...
Also, a little question, I use the onBind() method and the .aidl
interface methology to create my Service... Is there a correct way to
stop a Service ? And if so where should this be implemented (for
example unBind() in the onDestroy() method of my main Activity) ?
Thanks in advance Mark (or anyone who might shed some light on my
issue) !

On 11 feb, 17:11, "Mark Murphy" <mmur...@commonsware.com> wrote:
> > I'd like to know if it's possible to create a Singelton Service
> > throughout an application ?
>
> Services are singletons by their very nature.
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com

> Android App Developer Books:http://commonsware.com/books.html

Re: Singleton Service ??? MobDev 2/23/10 3:05 AM
Lol,
I see I actually forgot to place the question in the first part of my
previous post :D
That is : if a Service already is running, is there some way to bind
to it when my app starts up, and/or programmatically check if it's
already running ?
So that I won't be having 2 separate Service entities that do exactly
the same...
Re: Singleton Service ??? Kitzy 3/25/10 12:30 PM
You can call stopSelf () from within a service, or stopService
(Intent) from another activity.

Sincerely,
-Kitzy

On Feb 23, 5:05 am, MobDev <developm...@mobilaria.com> wrote:
> Lol,
> I see I actually forgot to place the question in the first part of my
> previous post :D
> That is : if aServicealready is running, is there some way to bind

> to it when my app starts up, and/or programmatically check if it's
> already running ?
> So that I won't be having 2 separateServiceentities that do exactly

> the same...
>
> On 23 feb, 11:44, MobDev <developm...@mobilaria.com> wrote:
>
> > actually I had a question regarding this...
> > I made aservicewhich plays an MP3, so it uses a single instance (in
> > the wholeservice) of MediaPlayer..
> > Still I noticed (by mistake because theServicedidn't get closed
> > while exiting my main Activity) that theServiceobviously kept

> > running, but when I restarted my app it created anotherServicewhich
> > also could play the MP3, thus creating a "mixing" effect, having the
> > same MP3 playing double... The second one I could stop through my App
> > but the first "lost" one couldn't be stopped...
> > To me this doesn't look like aSingleton'sbehaviour, I actually have
> > two seperate entities of aServicerunning in the system...

> > Also, a little question, I use the onBind() method and the .aidl
> > interface methology to create myService... Is there a correct way to
> > stop aService? And if so where should this be implemented (for

> > example unBind() in the onDestroy() method of my main Activity) ?
> > Thanks in advance Mark (or anyone who might shed some light on my
> > issue) !
>
> > On 11 feb, 17:11, "Mark Murphy" <mmur...@commonsware.com> wrote:
>
> > > > I'd like to know if it's possible to create a SingeltonService
> > > > throughout an application ?
>
> > > Services are singletons by their very nature.
>
> > > --
> > > Mark Murphy (a Commons Guy)http://commonsware.com
> > > Android App Developer Books:http://commonsware.com/books.html
>
>

Re: [android-developers] Re: Singleton Service ??? Dianne Hackborn 3/26/10 1:12 PM
Please look at the various service examples in ApiDemos, they cover a lot of different ways to interact with them.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-d...@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en