File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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: 41821
    
  62
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Passing a variable from Activity to a running Service?