After getting to know Android a bit better, I've found many solutions
which I will share with you:

1. I started the service by calling startService(intent) from the UI.
Furthermore, I send commands to the service by using startService
(intent), bundling value-pairs in the intent, and then reading them
(switching) in the onStart()-method in the service.

2. I could stop the service by calling stopService(intent), but I use
a command as explained above, and letting the service stop itself
using stopSelf(). I do this because I want to execute some methods
when shutting down the service, but ONLY when it is done explicitly in
the UI, not if the android framework shuts it down. Therefore I cannot
execute these methods in onDestroy().

3. I've programmatically registered the intents on the service using a
BroadcastReceiver. By doing it programmatically I'm able to stop
listening for the intents when the service stops and vice versa.

One last thing: I sometimes in the IU want to check whether my service
is running or not, and I've done this by implementing my service as a
singleton, creating a static variable telling if the service is
started or not.

Hope this might help other "newbies" ;)

Regards,

Jeppe

On 1 Nov., 16:53, Jeppebm <[email protected]> wrote:
> Hi,
>
> I'm rather new to Android, so please bear with me.
>
> I'm developing an application running a service in the background. The
> service is ONLY supposed to run when requested somewhere in the UI.
> The service must be able to be stopped through the UI as well.
>
> At the same time, while running, the service must be able to pick up
> intents such as "intent.action.DATA_SMS_RECEIVED" and
> "intent.action.NEW_OUTGOING_CALL".
>
> How do I go about this?
>
> 1. How to initially start the service? startService(intent) called
> from the UI right?
> 2. How to stop it again? How do I get a hold of it when it's time to
> stop it.
> 3. Should I register af Receiver to the service to catch the mentioned
> intents? And so, where to do this? Can I catch intents directly in the
> service?
>
> Thanks in advance!

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

Reply via email to