This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Android and the fly likes Passing a variable from Activity to a running Service? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Mobile » Android
Bookmark "Passing a variable from Activity to a running Service?" Watch "Passing a variable from Activity to a running Service?" New topic
Author

Passing a variable from Activity to a running Service?

Sean Michael Hayes
Ranch Hand

Joined: Feb 08, 2012
Posts: 54

What would be the best way of accomplishing this? The service is started on start-up of the application when the first activity loads. But later on in the application in a different specific activity I want to pass a variable to the service? I am new to services in Android and am wondering if anyone could point me in the right direction?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42035
    
  64
You would send an Intent to it that is targeted at its precise class. Something like this in the Activity:

and in the Service:


Ping & DNS - my free Android networking tools app
 
GeeCON Prague 2014
 
subject: Passing a variable from Activity to a running Service?