I have an application that listens to broadcasts and sends broadcasts.
When the application sends a broadcast it expects a broadcast back from another application.
I catch the broadcast in my receiver and then send the content to a regular java class called ‘decode’.
Here I check the contents of the broadcast and call a method on the mainActivity to launch another activity.
This mainActivity has no real UI, so I was thinking of making a service to replace it.
So I instead of calling mainActivity from decode, I would make a service and call a method from that service.
Now , since I have no experience with android services, is this a good case to use a service ?
Where can I find a good example of android services?
You’re right, this is the time to use a
Servicesince you should never call anActivitymethod from outside theActivity. I will give you the most basicServiceas a template, and then you can add stuff to it as you like:Now in order to start this service, you call the method
startServiceand to stop it, call the methodstopService. Now if you want to stop the service inside the service, for example when your work is done. You could callstopSelf();inside your service method. Google forstartServiceandstopServicein order to see what parameters are needed, and how to call them depending if you are inside anActivityor not, this is where you might need theContextif you call it from inside a class.http://developer.android.com/reference/android/app/Service.html